Mercurial > libervia-web
annotate browser_side/register.py @ 161:03ac7f51a35b
browser side: fixed registration:
- fixed warning messages (there are now 2 warning messages, one for login, one for registration)
- fixed login & register tab sizes
- added "INTERNAL" error, in case of something going really wrong at server side during account creation
- minor typo corrections
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Jan 2013 01:15:19 +0100 |
parents | ddfcc4cb6cee |
children | 9763dec220ed |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
131 | 6 Copyright (C) 2011, 2012 Jérôme Poisson <goffi@goffi.org> |
7 Copyright (C) 2011, 2012 Adrien Vigneron <adrienvigneron@mailoo.org> | |
0 | 8 |
9 This program is free software: you can redistribute it and/or modify | |
10 it under the terms of the GNU Affero General Public License as published by | |
11 the Free Software Foundation, either version 3 of the License, or | |
12 (at your option) any later version. | |
13 | |
14 This program is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU Affero General Public License for more details. | |
18 | |
19 You should have received a copy of the GNU Affero General Public License | |
20 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 """ | |
22 | |
23 #This page manage subscription and new account creation | |
24 import pyjd # this is dummy in pyjs | |
25 | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
26 from pyjamas.ui.SimplePanel import SimplePanel |
0 | 27 from pyjamas.ui.VerticalPanel import VerticalPanel |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
29 from pyjamas.ui.TabPanel import TabPanel |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
30 from pyjamas.ui.TabBar import TabBar |
0 | 31 from pyjamas.ui.Grid import Grid |
32 from pyjamas.ui.PasswordTextBox import PasswordTextBox | |
33 from pyjamas.ui.TextBox import TextBox | |
34 from pyjamas.ui.FormPanel import FormPanel | |
35 from pyjamas.ui.Button import Button | |
46 | 36 from pyjamas.ui.Label import Label |
37 from pyjamas.ui.CheckBox import CheckBox | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
38 from pyjamas.ui.PopupPanel import PopupPanel |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
39 from pyjamas.ui.Image import Image |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
40 from pyjamas.ui.Hidden import Hidden |
0 | 41 from pyjamas import Window |
42 from pyjamas.ui import HasAlignment | |
46 | 43 import re |
0 | 44 |
45 | |
46 class RegisterPanel(FormPanel): | |
47 | |
48 def __init__(self, callback): | |
49 """ | |
50 @param callback: method to call if login successful | |
51 """ | |
52 FormPanel.__init__(self) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
53 self.setSize('600px', '350px') |
0 | 54 self.callback = callback |
55 self.setMethod(FormPanel.METHOD_POST) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
56 main_panel = HorizontalPanel() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
57 main_panel.setStyleName('registerPanel_main') |
77 | 58 left_side = Image("media/libervia/register_left.png") |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
59 main_panel.add(left_side) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
60 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
61 ##TabPanel## |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
62 tab_bar = TabBar() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
63 tab_bar.setStyleName('registerPanel_tabs') |
67 | 64 self.right_side = TabPanel(tab_bar) |
65 self.right_side.setStyleName('registerPanel_right_side') | |
66 main_panel.add(self.right_side) | |
67 main_panel.setCellWidth(self.right_side, '100%') | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
68 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
69 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
70 ##Login tab## |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
71 login_tab = SimplePanel() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
72 login_tab.setStyleName('registerPanel_content') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
73 login_vpanel = VerticalPanel() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
74 login_tab.setWidget(login_vpanel) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
75 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
76 |
161 | 77 self.login_warning_msg = Label('') |
78 self.login_warning_msg.setVisible(False) | |
79 self.login_warning_msg.setStyleName('formWarning') | |
80 login_vpanel.add(self.login_warning_msg) | |
46 | 81 |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
82 login_label = Label('Login:') |
46 | 83 self.login_box = TextBox() |
84 self.login_box.setName("login") | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
85 login_pass_label = Label('Password:') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
86 login_pass_box = PasswordTextBox() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
87 login_pass_box.setName("login_password") |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
88 login_vpanel.add(login_label) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
89 login_vpanel.add(self.login_box) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
90 login_vpanel.add(login_pass_label) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
91 login_vpanel.add(login_pass_box) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
92 login_but = Button("Log in", getattr(self, "onLogin")) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
93 login_but.setStyleName('button') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
94 login_but.addStyleName('red') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
95 login_vpanel.add(login_but) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
96 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
97 #The hidden submit_type field |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
98 self.submit_type = Hidden('submit_type') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
99 login_vpanel.add(self.submit_type) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
100 |
46 | 101 |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
102 ##Register tab## |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
103 register_tab = SimplePanel() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
104 register_tab.setStyleName('registerPanel_content') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
105 register_vpanel = VerticalPanel() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
106 register_tab.setWidget(register_vpanel) |
46 | 107 |
161 | 108 self.register_warning_msg = Label('') |
109 self.register_warning_msg.setVisible(False) | |
110 self.register_warning_msg.setStyleName('formWarning') | |
111 register_vpanel.add(self.register_warning_msg) | |
112 | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
113 register_login_label = Label('Login:') |
67 | 114 self.register_login_box = TextBox() |
115 self.register_login_box.setName("register_login") | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
116 email_label = Label('E-mail:') |
46 | 117 self.email_box = TextBox() |
118 self.email_box.setName("email") | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
119 register_pass_label = Label('Password:') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
120 self.register_pass_box = PasswordTextBox() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
121 self.register_pass_box.setName("register_password") |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
122 register_vpanel.add(register_login_label) |
67 | 123 register_vpanel.add(self.register_login_box) |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
124 register_vpanel.add(email_label) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
125 register_vpanel.add(self.email_box) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
126 register_vpanel.add(register_pass_label) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
127 register_vpanel.add(self.register_pass_box) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
128 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
129 register_but = Button("Register", getattr(self, "onRegister")) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
130 register_but.setStyleName('button') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
131 register_but.addStyleName('red') |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
132 register_vpanel.add(register_but) |
46 | 133 |
67 | 134 self.right_side.add(login_tab, 'Login') |
135 self.right_side.add(register_tab, 'Register') | |
136 self.right_side.selectTab(0) | |
161 | 137 login_tab.setWidth(None) |
138 register_tab.setWidth(None) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
139 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
140 self.add(main_panel) |
0 | 141 self.addFormHandler(self) |
142 self.setAction('register_api/login') | |
143 | |
62 | 144 def onLogin(self, button): |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
145 self.submit_type.setValue('login') |
0 | 146 self.submit() |
46 | 147 |
62 | 148 def onRegister(self, button): |
67 | 149 if not re.match(r'^[a-z0-9_-]+$',self.register_login_box.getText(), re.IGNORECASE): |
161 | 150 self.register_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -') |
151 self.register_warning_msg.setVisible(True) | |
46 | 152 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE): |
161 | 153 self.register_warning_msg.setText('Invalid email address') |
154 self.register_warning_msg.setVisible(True) | |
46 | 155 else: |
161 | 156 self.register_warning_msg.setVisible(False) |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
157 self.submit_type.setValue('register') |
46 | 158 self.submit() |
159 | |
0 | 160 |
161 def onSubmit(self, event): | |
162 pass | |
163 | |
164 def onSubmitComplete(self, event): | |
165 result = event.getResults() | |
166 if result == "AUTH ERROR": | |
121 | 167 Window.alert('Your login and/or password is incorrect. Please try again') |
0 | 168 elif result == "LOGGED": |
169 self.callback() | |
62 | 170 elif result == "SESSION_ACTIVE": |
161 | 171 Window.alert('Session already active, this should not happen, please contact the author to fix it') |
46 | 172 elif result == "ALREADY EXISTS": |
161 | 173 self.register_warning_msg.setText('This login already exists, please choose an other one') |
174 self.register_warning_msg.setVisible(True) | |
175 elif result == "INTERNAL": | |
176 self.register_warning_msg.setText('SERVER ERROR: something went wrong during registration process, please contact the server administrator') | |
177 self.register_warning_msg.setVisible(True) | |
46 | 178 elif result == "REGISTRATION": |
161 | 179 self.login_warning_msg.setVisible(False) |
180 self.register_warning_msg.setVisible(False) | |
67 | 181 self.login_box.setText(self.register_login_box.getText()) |
182 self.register_login_box.setText('') | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
183 self.register_pass_box.setText('') |
67 | 184 self.email_box.setText('') |
185 self.right_side.selectTab(0) | |
46 | 186 Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO') |
0 | 187 else: |
188 Window.alert('Submit error: %s' % result) | |
189 | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
190 class RegisterBox(PopupPanel): |
0 | 191 |
192 def __init__(self, callback, *args,**kwargs): | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
193 PopupPanel.__init__(self,*args,**kwargs) |
0 | 194 _form = RegisterPanel(callback) |
195 self.setWidget(_form) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
196 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
197 def onWindowResized(self, width, height): |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
198 super(RegisterBox, self).onWindowResized(width, height) |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
199 self.centerBox() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
200 |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
201 def show(self): |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
202 super(RegisterBox, self).show() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
203 self.centerBox() |
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
204 |