annotate browser_side/register.py @ 65:8f421a12b8f9

browser side: register box CSS update
author Adrien Vigneron <adrienvigneron@mailoo.org>
date Wed, 15 Jun 2011 00:49:34 +0200
parents 12e889a683ce
children 9d8e79ac4c9c
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
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
31 from pyjamas.ui.Label import Label
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
32 from pyjamas.ui.CheckBox import CheckBox
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from pyjamas.ui.DialogBox import DialogBox
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from pyjamas import Window
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from pyjamas.ui import HasAlignment
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
36 import re
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
37
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
38
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
39
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
40
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
41 class RegisterPanel(FormPanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
42
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self, callback):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
44 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
45 @param callback: method to call if login successful
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
47 FormPanel.__init__(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.callback = callback
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.setMethod(FormPanel.METHOD_POST)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
50 vPanel = VerticalPanel()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
51 vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
52 self.warning_msg = Label()
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
53 self.warning_msg.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
54 self.warning_msg.setStyleName('formWarning')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
55 vPanel.add(self.warning_msg)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
56
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
57 self.login_box = TextBox()
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
58 self.login_box.setName("login")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
59 self.pass_box = PasswordTextBox()
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
60 self.pass_box.setName("password")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
61 login_grid = Grid(2, 2)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
62 login_grid.setText(0,0,"Login:")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
63 login_grid.setWidget(0,1, self.login_box)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
64 login_grid.setText(1,0, "Password:")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
65 login_grid.setWidget(1,1, self.pass_box)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
66 vPanel.add(login_grid)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
67
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
68 self.new_account = CheckBox('Register new account')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
69 self.new_account.setName('new_account')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
70 self.new_account.addClickListener(self.onNewAccountChecked)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
71 vPanel.add(self.new_account)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
72
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
73
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
74 self.email_box = TextBox()
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
75 self.email_box.setName("email")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
76 self.register_grid = Grid(1, 2)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
77 self.register_grid.setText(0,0,"email:")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
78 self.register_grid.setWidget(0,1, self.email_box)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
79 self.register_grid.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
80 vPanel.add(self.register_grid)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
81 self.info_register_lb = Label('Your password will be sent to the given email')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
82 self.info_register_lb.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
83 vPanel.add(self.register_grid)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
84 vPanel.add(self.info_register_lb)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
85
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
86 self.login_but = Button("Login", getattr(self, "onLogin"))
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
87 vPanel.add(self.login_but)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
88 self.register_but = Button("Register", getattr(self, "onRegister"))
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
89 self.register_but.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
90 vPanel.add(self.register_but)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.add(vPanel)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.addFormHandler(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.setAction('register_api/login')
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
94
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
95 def changeMode(self, mode):
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
96 """Change the configuration of the dialog
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
97 @param mode: "login" or "register"""
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
98 if mode == "register":
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
99 self.pass_box.setEnabled(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
100 self.register_grid.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
101 self.info_register_lb.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
102 self.login_but.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
103 self.register_but.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
104 self.new_account.setChecked(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
105 else:
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
106 self.pass_box.setEnabled(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
107 self.register_grid.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
108 self.info_register_lb.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
109 self.login_but.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
110 self.register_but.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
111 self.new_account.setChecked(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
112
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
113
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
114 def onNewAccountChecked(self, sender):
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
115 if sender.isChecked():
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
116 self.changeMode("register")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
117 else:
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
118 self.changeMode("login")
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
119
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 46
diff changeset
120 def onLogin(self, button):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self.submit()
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
122
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 46
diff changeset
123 def onRegister(self, button):
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
124 print self.login_box.getText()
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
125 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE):
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
126 self.warning_msg.setText('Invaling login, valid characters are a-z A-Z 0-9 _ -')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
127 self.warning_msg.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
128 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE):
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
129 self.warning_msg.setText('Invaling email address')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
130 self.warning_msg.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
131 else:
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
132 self.warning_msg.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
133 self.submit()
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
134
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
135
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
136 def onSubmit(self, event):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
137 pass
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
138
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def onSubmitComplete(self, event):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
140 result = event.getResults()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
141 if result == "AUTH ERROR":
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
142 Window.alert('You login and/or password is incorrect. Please try again')
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
143 elif result == "LOGGED":
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
144 self.callback()
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 46
diff changeset
145 elif result == "SESSION_ACTIVE":
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 46
diff changeset
146 Window.alert('Session already active, this should not happen, please contact contact the author to fix it')
46
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
147 elif result == "ALREADY EXISTS":
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
148 self.warning_msg.setText('This login already exists, please choose an other one')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
149 self.warning_msg.setVisible(True)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
150 elif result == "REGISTRATION":
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
151 self.warning_msg.setVisible(False)
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
152 self.changeMode('login')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
153 self.pass_box.setText('')
c3ee630914ba Account creation
Goffi <goffi@goffi.org>
parents: 43
diff changeset
154 Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO')
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
155 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
156 Window.alert('Submit error: %s' % result)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
157
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
158 class RegisterBox(DialogBox):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
159
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
160 def __init__(self, callback, *args,**kwargs):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
161 DialogBox.__init__(self,*args,**kwargs)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
162 _form = RegisterPanel(callback)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
163 self.setHTML('<b>You are not identified, please log in</b>')
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
164 self.setWidget(_form)