annotate browser_side/register.py @ 42:71a9cc9b9d57

Browser side: Tarot game - draw game managed - we can now play continuously \o/
author Goffi <goffi@goffi.org>
date Mon, 23 May 2011 00:45:19 +0200
parents c725b702e927
children a7ff1e6f1229
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
3
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
7
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
12
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
17
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
21
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
22 #This page manage subscription and new account creation
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import pyjd # this is dummy in pyjs
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
24
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.Grid import Grid
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.PasswordTextBox import PasswordTextBox
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.TextBox import TextBox
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.FormPanel import FormPanel
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.Button import Button
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.DialogBox import DialogBox
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas import Window
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from pyjamas.ui import HasAlignment
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
34
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
35
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
36
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
37
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class RegisterPanel(FormPanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
39
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def __init__(self, callback):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
42 @param callback: method to call if login successful
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
43 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
44 FormPanel.__init__(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.callback = callback
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.setMethod(FormPanel.METHOD_POST)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
47 vPanel = VerticalPanel()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
48 vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.loginBox = TextBox()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.loginBox.setName("login")
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 17
diff changeset
51 self.loginBox.setText("goffi_local")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.passBox = PasswordTextBox()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.passBox.setName("password")
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 17
diff changeset
54 self.passBox.setText("toto")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
55 grid = Grid(2, 2)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
56 grid.setText(0,0,"Login:")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
57 grid.setWidget(0,1, self.loginBox)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
58 grid.setText(1,0, "Password:")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
59 grid.setWidget(1,1, self.passBox)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
60 vPanel.add(grid)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
61 login_but = Button("Login", getattr(self, "onLogin"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
62 vPanel.add(login_but)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.add(vPanel)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.addFormHandler(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.setAction('register_api/login')
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
66
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def onLogin(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.submit()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
69
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def onSubmit(self, event):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
71 pass
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
72
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def onSubmitComplete(self, event):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
74 result = event.getResults()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
75 if result == "AUTH ERROR":
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
76 Window.alert('You login and/or password is incorrect. Please try again')
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
77 elif result == "LOGGED":
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.callback()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
79 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
80 Window.alert('Submit error: %s' % result)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
81
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
82 class RegisterBox(DialogBox):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
83
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def __init__(self, callback, *args,**kwargs):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
85 DialogBox.__init__(self,*args,**kwargs)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
86 _form = RegisterPanel(callback)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.setHTML('<b>You are not identified, please log in</b>')
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.setWidget(_form)