comparison browser_side/register.py @ 445:c0ff91cabea0

server_side, browser_side: new account password must contain at least 6 chars + cosmetic change for register warning message
author souliane <souliane@mailoo.org>
date Wed, 07 May 2014 19:29:10 +0200
parents 17259c2ff96f
children
comparison
equal deleted inserted replaced
444:b64e528fb524 445:c0ff91cabea0
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21 #This page manage subscription and new account creation 21 #This page manage subscription and new account creation
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 23
24 from constants import Const as C
25 from sat.core.i18n import _
24 from pyjamas.ui.SimplePanel import SimplePanel 26 from pyjamas.ui.SimplePanel import SimplePanel
25 from pyjamas.ui.VerticalPanel import VerticalPanel 27 from pyjamas.ui.VerticalPanel import VerticalPanel
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel 28 from pyjamas.ui.HorizontalPanel import HorizontalPanel
27 from pyjamas.ui.TabPanel import TabPanel 29 from pyjamas.ui.TabPanel import TabPanel
28 from pyjamas.ui.TabBar import TabBar 30 from pyjamas.ui.TabBar import TabBar
29 from pyjamas.ui.PasswordTextBox import PasswordTextBox 31 from pyjamas.ui.PasswordTextBox import PasswordTextBox
30 from pyjamas.ui.TextBox import TextBox 32 from pyjamas.ui.TextBox import TextBox
31 from pyjamas.ui.FormPanel import FormPanel 33 from pyjamas.ui.FormPanel import FormPanel
32 from pyjamas.ui.Button import Button 34 from pyjamas.ui.Button import Button
33 from pyjamas.ui.Label import Label 35 from pyjamas.ui.Label import Label
36 from pyjamas.ui.HTML import HTML
34 from pyjamas.ui.PopupPanel import PopupPanel 37 from pyjamas.ui.PopupPanel import PopupPanel
35 from pyjamas.ui.Image import Image 38 from pyjamas.ui.Image import Image
36 from pyjamas.ui.Hidden import Hidden 39 from pyjamas.ui.Hidden import Hidden
37 from pyjamas import Window 40 from pyjamas import Window
38 from pyjamas.ui.KeyboardListener import KEY_ENTER 41 from pyjamas.ui.KeyboardListener import KEY_ENTER
100 register_tab = SimplePanel() 103 register_tab = SimplePanel()
101 register_tab.setStyleName('registerPanel_content') 104 register_tab.setStyleName('registerPanel_content')
102 register_vpanel = VerticalPanel() 105 register_vpanel = VerticalPanel()
103 register_tab.setWidget(register_vpanel) 106 register_tab.setWidget(register_vpanel)
104 107
105 self.register_warning_msg = Label('') 108 self.register_warning_msg = HTML('')
106 self.register_warning_msg.setVisible(False) 109 self.register_warning_msg.setVisible(False)
107 self.register_warning_msg.setStyleName('formWarning') 110 self.register_warning_msg.setStyleName('formWarning')
108 register_vpanel.add(self.register_warning_msg) 111 register_vpanel.add(self.register_warning_msg)
109 112
110 register_login_label = Label('Login:') 113 register_login_label = Label('Login:')
173 176
174 def onKeyDown(self, sender, keycode, modifiers): 177 def onKeyDown(self, sender, keycode, modifiers):
175 pass 178 pass
176 179
177 def onLogin(self, button): 180 def onLogin(self, button):
178 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE): 181 if not re.match(r'^[a-z0-9_-]+$', self.login_box.getText(), re.IGNORECASE):
179 self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -') 182 self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -')
180 self.login_warning_msg.setVisible(True) 183 self.login_warning_msg.setVisible(True)
181 else: 184 else:
182 self.submit_type.setValue('login') 185 self.submit_type.setValue('login')
183 self.submit() 186 self.submit()
184 187
185 def onRegister(self, button): 188 def onRegister(self, button):
186 if not re.match(r'^[a-z0-9_-]+$',self.register_login_box.getText(), re.IGNORECASE): 189 if not re.match(r'^[a-z0-9_-]+$', self.register_login_box.getText(), re.IGNORECASE):
187 self.register_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -') 190 self.register_warning_msg.setHTML(_('Invalid login, valid characters<br>are a-z A-Z 0-9 _ -'))
188 self.register_warning_msg.setVisible(True) 191 self.register_warning_msg.setVisible(True)
189 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE): 192 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE):
190 self.register_warning_msg.setText('Invalid email address') 193 self.register_warning_msg.setHTML(_('Invalid email address'))
194 self.register_warning_msg.setVisible(True)
195 elif len(self.register_pass_box.getText()) < C.PASSWORD_MIN_LENGTH:
196 self.register_warning_msg.setHTML(_('Your password must contain<br>at least %d characters') % C.PASSWORD_MIN_LENGTH)
191 self.register_warning_msg.setVisible(True) 197 self.register_warning_msg.setVisible(True)
192 else: 198 else:
193 self.register_warning_msg.setVisible(False) 199 self.register_warning_msg.setVisible(False)
194 self.submit_type.setValue('register') 200 self.submit_type.setValue('register')
195 self.submit() 201 self.submit()
204 elif result == "LOGGED": 210 elif result == "LOGGED":
205 self.callback() 211 self.callback()
206 elif result == "SESSION_ACTIVE": 212 elif result == "SESSION_ACTIVE":
207 Window.alert('Session already active, this should not happen, please contact the author to fix it') 213 Window.alert('Session already active, this should not happen, please contact the author to fix it')
208 elif result == "ALREADY EXISTS": 214 elif result == "ALREADY EXISTS":
209 self.register_warning_msg.setText('This login already exists, please choose an other one') 215 self.register_warning_msg.setHTML('This login already exists,<br>please choose another one')
210 self.register_warning_msg.setVisible(True) 216 self.register_warning_msg.setVisible(True)
211 elif result == "INTERNAL": 217 elif result == "INTERNAL":
212 self.register_warning_msg.setText('SERVER ERROR: something went wrong during registration process, please contact the server administrator') 218 self.register_warning_msg.setHTML('SERVER ERROR: something went wrong during registration process, please contact the server administrator')
213 self.register_warning_msg.setVisible(True) 219 self.register_warning_msg.setVisible(True)
214 elif result == "REGISTRATION": 220 elif result == "REGISTRATION":
215 self.login_warning_msg.setVisible(False) 221 self.login_warning_msg.setVisible(False)
216 self.register_warning_msg.setVisible(False) 222 self.register_warning_msg.setVisible(False)
217 self.login_box.setText(self.register_login_box.getText()) 223 self.login_box.setText(self.register_login_box.getText())
224 self.login_pass_box.setText('')
218 self.register_login_box.setText('') 225 self.register_login_box.setText('')
219 self.register_pass_box.setText('') 226 self.register_pass_box.setText('')
220 self.email_box.setText('') 227 self.email_box.setText('')
221 self.right_side.selectTab(0) 228 self.right_side.selectTab(0)
222 self.login_pass_box.setFocus(True) 229 self.login_pass_box.setFocus(True)