Mercurial > libervia-web
comparison browser_side/register.py @ 46:c3ee630914ba
Account creation
* browser side:
- login dialog has been extended to manage subscription
* server side:
- SATActionIDHandler to manage replies to action
- account is created on subscribtion form, a password is created, and 2 emails are send (one to user, one to administrator)
- access of main microblog is set to open
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 May 2011 16:43:30 +0200 |
parents | a7ff1e6f1229 |
children | 12e889a683ce |
comparison
equal
deleted
inserted
replaced
45:7f106052326f | 46:c3ee630914ba |
---|---|
26 from pyjamas.ui.Grid import Grid | 26 from pyjamas.ui.Grid import Grid |
27 from pyjamas.ui.PasswordTextBox import PasswordTextBox | 27 from pyjamas.ui.PasswordTextBox import PasswordTextBox |
28 from pyjamas.ui.TextBox import TextBox | 28 from pyjamas.ui.TextBox import TextBox |
29 from pyjamas.ui.FormPanel import FormPanel | 29 from pyjamas.ui.FormPanel import FormPanel |
30 from pyjamas.ui.Button import Button | 30 from pyjamas.ui.Button import Button |
31 from pyjamas.ui.Label import Label | |
32 from pyjamas.ui.CheckBox import CheckBox | |
31 from pyjamas.ui.DialogBox import DialogBox | 33 from pyjamas.ui.DialogBox import DialogBox |
32 from pyjamas import Window | 34 from pyjamas import Window |
33 from pyjamas.ui import HasAlignment | 35 from pyjamas.ui import HasAlignment |
36 import re | |
34 | 37 |
35 | 38 |
36 | 39 |
37 | 40 |
38 class RegisterPanel(FormPanel): | 41 class RegisterPanel(FormPanel): |
44 FormPanel.__init__(self) | 47 FormPanel.__init__(self) |
45 self.callback = callback | 48 self.callback = callback |
46 self.setMethod(FormPanel.METHOD_POST) | 49 self.setMethod(FormPanel.METHOD_POST) |
47 vPanel = VerticalPanel() | 50 vPanel = VerticalPanel() |
48 vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) | 51 vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) |
49 self.loginBox = TextBox() | 52 self.warning_msg = Label() |
50 self.loginBox.setName("login") | 53 self.warning_msg.setVisible(False) |
51 self.passBox = PasswordTextBox() | 54 self.warning_msg.setStyleName('formWarning') |
52 self.passBox.setName("password") | 55 vPanel.add(self.warning_msg) |
53 grid = Grid(2, 2) | 56 |
54 grid.setText(0,0,"Login:") | 57 self.login_box = TextBox() |
55 grid.setWidget(0,1, self.loginBox) | 58 self.login_box.setName("login") |
56 grid.setText(1,0, "Password:") | 59 self.pass_box = PasswordTextBox() |
57 grid.setWidget(1,1, self.passBox) | 60 self.pass_box.setName("password") |
58 vPanel.add(grid) | 61 login_grid = Grid(2, 2) |
59 login_but = Button("Login", getattr(self, "onLogin")) | 62 login_grid.setText(0,0,"Login:") |
60 vPanel.add(login_but) | 63 login_grid.setWidget(0,1, self.login_box) |
64 login_grid.setText(1,0, "Password:") | |
65 login_grid.setWidget(1,1, self.pass_box) | |
66 vPanel.add(login_grid) | |
67 | |
68 self.new_account = CheckBox('Register new account') | |
69 self.new_account.setName('new_account') | |
70 self.new_account.addClickListener(self.onNewAccountChecked) | |
71 vPanel.add(self.new_account) | |
72 | |
73 | |
74 self.email_box = TextBox() | |
75 self.email_box.setName("email") | |
76 self.register_grid = Grid(1, 2) | |
77 self.register_grid.setText(0,0,"email:") | |
78 self.register_grid.setWidget(0,1, self.email_box) | |
79 self.register_grid.setVisible(False) | |
80 vPanel.add(self.register_grid) | |
81 self.info_register_lb = Label('Your password will be sent to the given email') | |
82 self.info_register_lb.setVisible(False) | |
83 vPanel.add(self.register_grid) | |
84 vPanel.add(self.info_register_lb) | |
85 | |
86 self.login_but = Button("Login", getattr(self, "onLogin")) | |
87 vPanel.add(self.login_but) | |
88 self.register_but = Button("Register", getattr(self, "onRegister")) | |
89 self.register_but.setVisible(False) | |
90 vPanel.add(self.register_but) | |
61 self.add(vPanel) | 91 self.add(vPanel) |
62 self.addFormHandler(self) | 92 self.addFormHandler(self) |
63 self.setAction('register_api/login') | 93 self.setAction('register_api/login') |
64 | 94 |
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 | |
65 def onLogin(self): | 120 def onLogin(self): |
66 self.submit() | 121 self.submit() |
122 | |
123 def onRegister(self): | |
124 print self.login_box.getText() | |
125 if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE): | |
126 self.warning_msg.setText('Invaling login, valid characters are a-z A-Z 0-9 _ -') | |
127 self.warning_msg.setVisible(True) | |
128 elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE): | |
129 self.warning_msg.setText('Invaling email address') | |
130 self.warning_msg.setVisible(True) | |
131 else: | |
132 self.warning_msg.setVisible(False) | |
133 self.submit() | |
134 | |
67 | 135 |
68 def onSubmit(self, event): | 136 def onSubmit(self, event): |
69 pass | 137 pass |
70 | 138 |
71 def onSubmitComplete(self, event): | 139 def onSubmitComplete(self, event): |
72 result = event.getResults() | 140 result = event.getResults() |
73 if result == "AUTH ERROR": | 141 if result == "AUTH ERROR": |
74 Window.alert('You login and/or password is incorrect. Please try again') | 142 Window.alert('You login and/or password is incorrect. Please try again') |
75 elif result == "LOGGED": | 143 elif result == "LOGGED": |
76 self.callback() | 144 self.callback() |
145 elif result == "ALREADY EXISTS": | |
146 self.warning_msg.setText('This login already exists, please choose an other one') | |
147 self.warning_msg.setVisible(True) | |
148 elif result == "REGISTRATION": | |
149 self.warning_msg.setVisible(False) | |
150 self.changeMode('login') | |
151 self.pass_box.setText('') | |
152 Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO') | |
77 else: | 153 else: |
78 Window.alert('Submit error: %s' % result) | 154 Window.alert('Submit error: %s' % result) |
79 | 155 |
80 class RegisterBox(DialogBox): | 156 class RegisterBox(DialogBox): |
81 | 157 |