comparison browser_side/register.py @ 66:9d8e79ac4c9c

Login/Register box: integration of Adrien Vigneron's design
author Goffi <goffi@goffi.org>
date Wed, 15 Jun 2011 00:52:02 +0200
parents 12e889a683ce
children b096facaa5b3
comparison
equal deleted inserted replaced
65:8f421a12b8f9 66:9d8e79ac4c9c
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 """ 4 """
5 Libervia: a Salut à Toi frontend 5 Libervia: a Salut à Toi frontend
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) 6 Copyright (C) 2011 Jérôme Poisson <goffi@goffi.org>
7 Copyright (C) 2011 Adrien Vigneron <adrienvigneron@mailoo.org>
7 8
8 This program is free software: you can redistribute it and/or modify 9 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by 10 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or 11 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version. 12 (at your option) any later version.
20 """ 21 """
21 22
22 #This page manage subscription and new account creation 23 #This page manage subscription and new account creation
23 import pyjd # this is dummy in pyjs 24 import pyjd # this is dummy in pyjs
24 25
26 from pyjamas.ui.SimplePanel import SimplePanel
25 from pyjamas.ui.VerticalPanel import VerticalPanel 27 from pyjamas.ui.VerticalPanel import VerticalPanel
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel
29 from pyjamas.ui.TabPanel import TabPanel
30 from pyjamas.ui.TabBar import TabBar
26 from pyjamas.ui.Grid import Grid 31 from pyjamas.ui.Grid import Grid
27 from pyjamas.ui.PasswordTextBox import PasswordTextBox 32 from pyjamas.ui.PasswordTextBox import PasswordTextBox
28 from pyjamas.ui.TextBox import TextBox 33 from pyjamas.ui.TextBox import TextBox
29 from pyjamas.ui.FormPanel import FormPanel 34 from pyjamas.ui.FormPanel import FormPanel
30 from pyjamas.ui.Button import Button 35 from pyjamas.ui.Button import Button
31 from pyjamas.ui.Label import Label 36 from pyjamas.ui.Label import Label
32 from pyjamas.ui.CheckBox import CheckBox 37 from pyjamas.ui.CheckBox import CheckBox
33 from pyjamas.ui.DialogBox import DialogBox 38 from pyjamas.ui.PopupPanel import PopupPanel
39 from pyjamas.ui.Image import Image
40 from pyjamas.ui.Hidden import Hidden
34 from pyjamas import Window 41 from pyjamas import Window
35 from pyjamas.ui import HasAlignment 42 from pyjamas.ui import HasAlignment
36 import re 43 import re
37
38
39 44
40 45
41 class RegisterPanel(FormPanel): 46 class RegisterPanel(FormPanel):
42 47
43 def __init__(self, callback): 48 def __init__(self, callback):
44 """ 49 """
45 @param callback: method to call if login successful 50 @param callback: method to call if login successful
46 """ 51 """
47 FormPanel.__init__(self) 52 FormPanel.__init__(self)
53 self.setSize('600px', '350px')
48 self.callback = callback 54 self.callback = callback
49 self.setMethod(FormPanel.METHOD_POST) 55 self.setMethod(FormPanel.METHOD_POST)
50 vPanel = VerticalPanel() 56 main_panel = HorizontalPanel()
51 vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) 57 main_panel.setStyleName('registerPanel_main')
58 left_side = Image("register_left.png")
59 main_panel.add(left_side)
60
61 ##TabPanel##
62 tab_bar = TabBar()
63 tab_bar.setStyleName('registerPanel_tabs')
64 right_side = TabPanel(tab_bar)
65 right_side.setStyleName('registerPanel_right_side')
66 main_panel.add(right_side)
67 main_panel.setCellWidth(right_side, '100%')
68
69
70 ##Login tab##
71 login_tab = SimplePanel()
72 login_tab.setStyleName('registerPanel_content')
73 login_vpanel = VerticalPanel()
74 login_tab.setWidget(login_vpanel)
75
76
52 self.warning_msg = Label() 77 self.warning_msg = Label()
53 self.warning_msg.setVisible(False) 78 self.warning_msg.setVisible(False)
54 self.warning_msg.setStyleName('formWarning') 79 self.warning_msg.setStyleName('formWarning')
55 vPanel.add(self.warning_msg) 80 #login_vpanel.add(self.warning_msg)
56 81
82 login_label = Label('Login:')
57 self.login_box = TextBox() 83 self.login_box = TextBox()
58 self.login_box.setName("login") 84 self.login_box.setName("login")
59 self.pass_box = PasswordTextBox() 85 login_pass_label = Label('Password:')
60 self.pass_box.setName("password") 86 login_pass_box = PasswordTextBox()
61 login_grid = Grid(2, 2) 87 login_pass_box.setName("login_password")
62 login_grid.setText(0,0,"Login:") 88 login_vpanel.add(login_label)
63 login_grid.setWidget(0,1, self.login_box) 89 login_vpanel.add(self.login_box)
64 login_grid.setText(1,0, "Password:") 90 login_vpanel.add(login_pass_label)
65 login_grid.setWidget(1,1, self.pass_box) 91 login_vpanel.add(login_pass_box)
66 vPanel.add(login_grid) 92 login_but = Button("Log in", getattr(self, "onLogin"))
93 login_but.setStyleName('button')
94 login_but.addStyleName('red')
95 login_vpanel.add(login_but)
96
97 #The hidden submit_type field
98 self.submit_type = Hidden('submit_type')
99 login_vpanel.add(self.submit_type)
100
67 101
68 self.new_account = CheckBox('Register new account') 102 ##Register tab##
69 self.new_account.setName('new_account') 103 register_tab = SimplePanel()
70 self.new_account.addClickListener(self.onNewAccountChecked) 104 register_tab.setStyleName('registerPanel_content')
71 vPanel.add(self.new_account) 105 register_vpanel = VerticalPanel()
106 register_tab.setWidget(register_vpanel)
72 107
73 108 register_login_label = Label('Login:')
109 register_login_box = TextBox()
110 register_login_box.setName("register_login")
111 email_label = Label('E-mail:')
74 self.email_box = TextBox() 112 self.email_box = TextBox()
75 self.email_box.setName("email") 113 self.email_box.setName("email")
76 self.register_grid = Grid(1, 2) 114 register_pass_label = Label('Password:')
77 self.register_grid.setText(0,0,"email:") 115 self.register_pass_box = PasswordTextBox()
78 self.register_grid.setWidget(0,1, self.email_box) 116 self.register_pass_box.setName("register_password")
79 self.register_grid.setVisible(False) 117 register_vpanel.add(register_login_label)
80 vPanel.add(self.register_grid) 118 register_vpanel.add(register_login_box)
81 self.info_register_lb = Label('Your password will be sent to the given email') 119 register_vpanel.add(email_label)
82 self.info_register_lb.setVisible(False) 120 register_vpanel.add(self.email_box)
83 vPanel.add(self.register_grid) 121 register_vpanel.add(register_pass_label)
84 vPanel.add(self.info_register_lb) 122 register_vpanel.add(self.register_pass_box)
123
124 register_but = Button("Register", getattr(self, "onRegister"))
125 register_but.setStyleName('button')
126 register_but.addStyleName('red')
127 register_vpanel.add(register_but)
85 128
86 self.login_but = Button("Login", getattr(self, "onLogin")) 129 right_side.add(login_tab, 'Login')
87 vPanel.add(self.login_but) 130 right_side.add(register_tab, 'Register')
88 self.register_but = Button("Register", getattr(self, "onRegister")) 131 right_side.selectTab(0)
89 self.register_but.setVisible(False) 132
90 vPanel.add(self.register_but) 133 self.add(main_panel)
91 self.add(vPanel)
92 self.addFormHandler(self) 134 self.addFormHandler(self)
93 self.setAction('register_api/login') 135 self.setAction('register_api/login')
94 136
95 def changeMode(self, mode):
96 """Change the configuration of the dialog
97 @param mode: "login" or "register"""
98 if mode == "register":
99 self.pass_box.setEnabled(False)
100 self.register_grid.setVisible(True)
101 self.info_register_lb.setVisible(True)
102 self.login_but.setVisible(False)
103 self.register_but.setVisible(True)
104 self.new_account.setChecked(True)
105 else:
106 self.pass_box.setEnabled(True)
107 self.register_grid.setVisible(False)
108 self.info_register_lb.setVisible(False)
109 self.login_but.setVisible(True)
110 self.register_but.setVisible(False)
111 self.new_account.setChecked(False)
112
113
114 def onNewAccountChecked(self, sender):
115 if sender.isChecked():
116 self.changeMode("register")
117 else:
118 self.changeMode("login")
119
120 def onLogin(self, button): 137 def onLogin(self, button):
138 self.submit_type.setValue('login')
121 self.submit() 139 self.submit()
122 140
123 def onRegister(self, button): 141 def onRegister(self, button):
124 print self.login_box.getText() 142 print self.login_box.getText()
125 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE): 143 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE):
128 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE): 146 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE):
129 self.warning_msg.setText('Invaling email address') 147 self.warning_msg.setText('Invaling email address')
130 self.warning_msg.setVisible(True) 148 self.warning_msg.setVisible(True)
131 else: 149 else:
132 self.warning_msg.setVisible(False) 150 self.warning_msg.setVisible(False)
151 self.submit_type.setValue('register')
133 self.submit() 152 self.submit()
134 153
135 154
136 def onSubmit(self, event): 155 def onSubmit(self, event):
137 pass 156 pass
147 elif result == "ALREADY EXISTS": 166 elif result == "ALREADY EXISTS":
148 self.warning_msg.setText('This login already exists, please choose an other one') 167 self.warning_msg.setText('This login already exists, please choose an other one')
149 self.warning_msg.setVisible(True) 168 self.warning_msg.setVisible(True)
150 elif result == "REGISTRATION": 169 elif result == "REGISTRATION":
151 self.warning_msg.setVisible(False) 170 self.warning_msg.setVisible(False)
152 self.changeMode('login') 171 self.register_pass_box.setText('')
153 self.pass_box.setText('')
154 Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO') 172 Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO')
155 else: 173 else:
156 Window.alert('Submit error: %s' % result) 174 Window.alert('Submit error: %s' % result)
157 175
158 class RegisterBox(DialogBox): 176 class RegisterBox(PopupPanel):
159 177
160 def __init__(self, callback, *args,**kwargs): 178 def __init__(self, callback, *args,**kwargs):
161 DialogBox.__init__(self,*args,**kwargs) 179 PopupPanel.__init__(self,*args,**kwargs)
162 _form = RegisterPanel(callback) 180 _form = RegisterPanel(callback)
163 self.setHTML('<b>You are not identified, please log in</b>')
164 self.setWidget(_form) 181 self.setWidget(_form)
182
183 def onWindowResized(self, width, height):
184 super(RegisterBox, self).onWindowResized(width, height)
185 self.centerBox()
186
187 def show(self):
188 super(RegisterBox, self).show()
189 self.centerBox()
190