comparison src/browser/sat_browser/register.py @ 729:273b39f04d8e

browser_side: change login and register panels (makes it more visible and less confusing)
author souliane <souliane@mailoo.org>
date Wed, 21 Oct 2015 14:23:53 +0200
parents 9877607c719a
children 8ac862f6e5b3
comparison
equal deleted inserted replaced
728:9d35d75566fb 729:273b39f04d8e
24 from sat.core.i18n import _ 24 from sat.core.i18n import _
25 25
26 from pyjamas.ui.SimplePanel import SimplePanel 26 from pyjamas.ui.SimplePanel import SimplePanel
27 from pyjamas.ui.VerticalPanel import VerticalPanel 27 from pyjamas.ui.VerticalPanel import VerticalPanel
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel 28 from pyjamas.ui.HorizontalPanel import HorizontalPanel
29 from pyjamas.ui.TabPanel import TabPanel 29 from pyjamas.ui.StackPanel import StackPanel
30 from pyjamas.ui.TabBar import TabBar
31 from pyjamas.ui.PasswordTextBox import PasswordTextBox 30 from pyjamas.ui.PasswordTextBox import PasswordTextBox
32 from pyjamas.ui.TextBox import TextBox 31 from pyjamas.ui.TextBox import TextBox
33 from pyjamas.ui.FormPanel import FormPanel 32 from pyjamas.ui.FormPanel import FormPanel
34 from pyjamas.ui.Button import Button 33 from pyjamas.ui.Button import Button
35 from pyjamas.ui.Label import Label 34 from pyjamas.ui.Label import Label
59 main_panel = HorizontalPanel() 58 main_panel = HorizontalPanel()
60 main_panel.setStyleName('registerPanel_main') 59 main_panel.setStyleName('registerPanel_main')
61 left_side = Image("media/libervia/register_left.png") 60 left_side = Image("media/libervia/register_left.png")
62 main_panel.add(left_side) 61 main_panel.add(left_side)
63 62
64 ##TabPanel## 63 ##StackPanel##
65 tab_bar = TabBar() 64 self.right_side = StackPanel(StyleName='registerPanel_right_side')
66 tab_bar.setStyleName('registerPanel_tabs')
67 self.right_side = TabPanel(tab_bar)
68 self.right_side.setStyleName('registerPanel_right_side')
69 main_panel.add(self.right_side) 65 main_panel.add(self.right_side)
70 main_panel.setCellWidth(self.right_side, '100%') 66 main_panel.setCellWidth(self.right_side, '100%')
71 67
72 ##Login tab## 68 ##Login stack##
73 login_tab = SimplePanel() 69 login_stack = SimplePanel()
74 login_tab.setStyleName('registerPanel_content') 70 login_stack.setStyleName('registerPanel_content')
75 login_vpanel = VerticalPanel() 71 login_vpanel = VerticalPanel()
76 login_tab.setWidget(login_vpanel) 72 login_stack.setWidget(login_vpanel)
77 73
78 self.login_warning_msg = Label('') 74 self.login_warning_msg = HTML('')
79 self.login_warning_msg.setVisible(False)
80 self.login_warning_msg.setStyleName('formWarning') 75 self.login_warning_msg.setStyleName('formWarning')
81 login_vpanel.add(self.login_warning_msg) 76 login_vpanel.add(self.login_warning_msg)
82 77
83 login_label = Label('Login:') 78 login_label = Label('Login:')
84 self.login_box = TextBox() 79 self.login_box = TextBox()
100 95
101 #The hidden submit_type field 96 #The hidden submit_type field
102 self.submit_type = Hidden('submit_type') 97 self.submit_type = Hidden('submit_type')
103 login_vpanel.add(self.submit_type) 98 login_vpanel.add(self.submit_type)
104 99
105 ##Register tab## 100 ##Register stack##
106 register_tab = SimplePanel() 101 register_stack = SimplePanel()
107 register_tab.setStyleName('registerPanel_content') 102 register_stack.setStyleName('registerPanel_content')
108 register_vpanel = VerticalPanel() 103 register_vpanel = VerticalPanel()
109 register_tab.setWidget(register_vpanel) 104 register_stack.setWidget(register_vpanel)
110 105
111 self.register_warning_msg = HTML('') 106 self.register_warning_msg = HTML('')
112 self.register_warning_msg.setVisible(False)
113 self.register_warning_msg.setStyleName('formWarning') 107 self.register_warning_msg.setStyleName('formWarning')
114 register_vpanel.add(self.register_warning_msg) 108 register_vpanel.add(self.register_warning_msg)
115 109
116 register_login_label = Label('Login:') 110 register_login_label = Label('Login:')
117 self.register_login_box = TextBox() 111 self.register_login_box = TextBox()
130 register_vpanel.add(email_label) 124 register_vpanel.add(email_label)
131 register_vpanel.add(self.email_box) 125 register_vpanel.add(self.email_box)
132 register_vpanel.add(register_pass_label) 126 register_vpanel.add(register_pass_label)
133 register_vpanel.add(self.register_pass_box) 127 register_vpanel.add(self.register_pass_box)
134 128
135 register_but = Button("Register", getattr(self, "onRegister")) 129 register_but = Button("Register a new account", getattr(self, "onRegister"))
136 register_but.setStyleName('button') 130 register_but.setStyleName('button')
137 register_but.addStyleName('red') 131 register_but.addStyleName('red')
138 register_vpanel.add(register_but) 132 register_vpanel.add(register_but)
139 133
140 self.right_side.add(login_tab, 'Login') 134 self.right_side.add(login_stack, 'Return to the login screen')
141 self.right_side.add(register_tab, 'Register') 135 self.right_side.add(register_stack, 'No account yet? Create a new one!')
142 self.right_side.addTabListener(self) 136 self.right_side.addStackChangeListener(self)
143 self.right_side.selectTab(1) 137 login_stack.setWidth(None)
144 login_tab.setWidth(None) 138 register_stack.setWidth(None)
145 register_tab.setWidth(None)
146 139
147 self.add(main_panel) 140 self.add(main_panel)
148 self.addFormHandler(self) 141 self.addFormHandler(self)
149 self.setAction('register_api/login') 142 self.setAction('register_api/login')
150 143
151 def onBeforeTabSelected(self, sender, tabIndex): 144 def onStackChanged(self, sender, index):
152 return True 145 if index == 0:
153
154 def onTabSelected(self, sender, tabIndex):
155 if tabIndex == 0:
156 self.login_box.setFocus(True) 146 self.login_box.setFocus(True)
157 elif tabIndex == 1: 147 elif index == 1:
158 self.register_login_box.setFocus(True) 148 self.register_login_box.setFocus(True)
159 149
160 def onKeyPress(self, sender, keycode, modifiers): 150 def onKeyPress(self, sender, keycode, modifiers):
161 if keycode == KEY_ENTER: 151 if keycode == KEY_ENTER:
162 # Browsers offer an auto-completion feature to any 152 # Browsers offer an auto-completion feature to any
181 pass 171 pass
182 172
183 def onLogin(self, button): 173 def onLogin(self, button):
184 if not re.match(r'^[a-z0-9_-]+$', self.login_box.getText(), re.IGNORECASE): 174 if not re.match(r'^[a-z0-9_-]+$', self.login_box.getText(), re.IGNORECASE):
185 self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -') 175 self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -')
186 self.login_warning_msg.setVisible(True)
187 else: 176 else:
188 self.submit_type.setValue('login') 177 self.submit_type.setValue('login')
189 self.submit(None) 178 self.submit(None)
190 179
191 def onRegister(self, button): 180 def onRegister(self, button):
192 # XXX: for now libervia forces the creation to lower case 181 # XXX: for now libervia forces the creation to lower case
193 self.register_login_box.setText(self.register_login_box.getText().lower()) 182 self.register_login_box.setText(self.register_login_box.getText().lower())
194 if not re.match(r'^[a-z0-9_-]+$', self.register_login_box.getText(), re.IGNORECASE): 183 if not re.match(r'^[a-z0-9_-]+$', self.register_login_box.getText(), re.IGNORECASE):
195 self.register_warning_msg.setHTML(_('Invalid login, valid characters<br>are a-z A-Z 0-9 _ -')) 184 self.register_warning_msg.setHTML(_('Invalid login, valid characters<br>are a-z A-Z 0-9 _ -'))
196 self.register_warning_msg.setVisible(True)
197 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE): 185 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE):
198 self.register_warning_msg.setHTML(_('Invalid email address')) 186 self.register_warning_msg.setHTML(_('Invalid email address'))
199 self.register_warning_msg.setVisible(True)
200 elif len(self.register_pass_box.getText()) < C.PASSWORD_MIN_LENGTH: 187 elif len(self.register_pass_box.getText()) < C.PASSWORD_MIN_LENGTH:
201 self.register_warning_msg.setHTML(_('Your password must contain<br>at least %d characters') % C.PASSWORD_MIN_LENGTH) 188 self.register_warning_msg.setHTML(_('Your password must contain<br>at least %d characters.') % C.PASSWORD_MIN_LENGTH)
202 self.register_warning_msg.setVisible(True)
203 else: 189 else:
204 self.register_warning_msg.setVisible(False) 190 self.register_warning_msg.setHTML("")
205 self.submit_type.setValue('register') 191 self.submit_type.setValue('register')
206 self.submit(None) 192 self.submit(None)
207 193
208 def onSubmit(self, event): 194 def onSubmit(self, event):
209 pass 195 pass
210 196
211 def onSubmitComplete(self, event): 197 def onSubmitComplete(self, event):
212 result = event.getResults() 198 result = event.getResults()
213 if result == C.PROFILE_AUTH_ERROR: 199 if result == C.PROFILE_AUTH_ERROR:
214 Window.alert(_('Your login and/or password is incorrect. Please try again')) 200 self.login_warning_msg.setHTML(_('Your login and/or password is incorrect. Please try again.'))
215 elif result == C.XMPP_AUTH_ERROR: 201 elif result == C.XMPP_AUTH_ERROR:
216 # TODO: call stdui action CHANGE_XMPP_PASSWD_ID as it's done in primitivus 202 # TODO: call stdui action CHANGE_XMPP_PASSWD_ID as it's done in primitivus
217 Window.alert(_(u'Your SàT profile has been authenticated but the associated XMPP account failed to connect. Please use another SàT frontend to set another XMPP password.')) 203 Window.alert(_(u'Your SàT profile has been authenticated but the associated XMPP account failed to connect. Please use another SàT frontend to set another XMPP password.'))
218 elif result == C.PROFILE_LOGGED: 204 elif result == C.PROFILE_LOGGED:
219 self.callback() 205 self.callback()
220 elif result == C.SESSION_ACTIVE: 206 elif result == C.SESSION_ACTIVE:
221 Window.alert(_('Session already active, this should not happen, please contact the author to fix it')) 207 Window.alert(_('Session already active, this should not happen, please contact the author to fix it.'))
222 elif result == C.NO_REPLY: 208 elif result == C.NO_REPLY:
223 Window.alert(_("Did not receive a reply (the timeout expired or the connection is broken)")) 209 Window.alert(_("Did not receive a reply (the timeout expired or the connection is broken)."))
224 elif result == C.ALREADY_EXISTS: 210 elif result == C.ALREADY_EXISTS:
225 self.register_warning_msg.setHTML(_('This login already exists,<br>please choose another one')) 211 self.register_warning_msg.setHTML(_('This login already exists,<br>please choose another one.'))
226 self.register_warning_msg.setVisible(True)
227 elif result == C.INTERNAL_ERROR: 212 elif result == C.INTERNAL_ERROR:
228 self.register_warning_msg.setHTML(_('SERVER ERROR: something went wrong during registration process, please contact the server administrator')) 213 self.register_warning_msg.setHTML(_('An registration error occurred, please contact the server administrator.'))
229 self.register_warning_msg.setVisible(True)
230 elif result == C.REGISTRATION_SUCCEED: 214 elif result == C.REGISTRATION_SUCCEED:
231 self.login_warning_msg.setVisible(False) 215 self.login_warning_msg.setHTML("")
232 self.register_warning_msg.setVisible(False) 216 self.register_warning_msg.setHTML("")
233 self.login_box.setText(self.register_login_box.getText()) 217 self.login_box.setText(self.register_login_box.getText())
234 self.login_pass_box.setText('') 218 self.login_pass_box.setText('')
235 self.register_login_box.setText('') 219 self.register_login_box.setText('')
236 self.register_pass_box.setText('') 220 self.register_pass_box.setText('')
237 self.email_box.setText('') 221 self.email_box.setText('')
238 self.right_side.selectTab(0) 222 self.right_side.showStack(0)
239 self.login_pass_box.setFocus(True) 223 self.login_pass_box.setFocus(True)
240 Window.alert(_('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO')) 224 Window.alert(_('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO.'))
241 else: 225 else:
242 Window.alert(_('Submit error: %s' % result)) 226 Window.alert(_('Submit error: %s' % result))
243 227
244 228
245 class RegisterBox(PopupPanel): 229 class RegisterBox(PopupPanel):