0
|
1 #!/usr/bin/python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 """ |
|
5 Libervia: a Salut à Toi frontend |
|
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
|
7 |
|
8 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 the Free Software Foundation, either version 3 of the License, or |
|
11 (at your option) any later version. |
|
12 |
|
13 This program is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU Affero General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU Affero General Public License |
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 """ |
|
21 |
|
22 #This page manage subscription and new account creation |
|
23 import pyjd # this is dummy in pyjs |
|
24 |
|
25 from pyjamas.ui.VerticalPanel import VerticalPanel |
|
26 from pyjamas.ui.Grid import Grid |
|
27 from pyjamas.ui.PasswordTextBox import PasswordTextBox |
|
28 from pyjamas.ui.TextBox import TextBox |
|
29 from pyjamas.ui.FormPanel import FormPanel |
|
30 from pyjamas.ui.Button import Button |
|
31 from pyjamas.ui.DialogBox import DialogBox |
|
32 from pyjamas import Window |
|
33 from pyjamas.ui import HasAlignment |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 class RegisterPanel(FormPanel): |
|
39 |
|
40 def __init__(self, callback): |
|
41 """ |
|
42 @param callback: method to call if login successful |
|
43 """ |
|
44 FormPanel.__init__(self) |
|
45 self.callback = callback |
|
46 self.setMethod(FormPanel.METHOD_POST) |
|
47 vPanel = VerticalPanel() |
|
48 vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) |
|
49 self.loginBox = TextBox() |
|
50 self.loginBox.setName("login") |
|
51 self.passBox = PasswordTextBox() |
|
52 self.passBox.setName("password") |
|
53 grid = Grid(2, 2) |
|
54 grid.setText(0,0,"Login:") |
|
55 grid.setWidget(0,1, self.loginBox) |
|
56 grid.setText(1,0, "Password:") |
|
57 grid.setWidget(1,1, self.passBox) |
|
58 vPanel.add(grid) |
|
59 login_but = Button("Login", getattr(self, "onLogin")) |
|
60 vPanel.add(login_but) |
|
61 self.add(vPanel) |
|
62 self.addFormHandler(self) |
|
63 self.setAction('register_api/login') |
|
64 |
|
65 def onLogin(self): |
|
66 self.submit() |
|
67 |
|
68 def onSubmit(self, event): |
|
69 pass |
|
70 |
|
71 def onSubmitComplete(self, event): |
|
72 result = event.getResults() |
|
73 if result == "AUTH ERROR": |
|
74 Window.alert('You login and/or password is incorrect. Please try again') |
|
75 elif result == "LOGGED": |
|
76 self.callback() |
|
77 else: |
|
78 Window.alert('Submit error: %s' % result) |
|
79 |
|
80 class RegisterBox(DialogBox): |
|
81 |
|
82 def __init__(self, callback, *args,**kwargs): |
|
83 DialogBox.__init__(self,*args,**kwargs) |
|
84 _form = RegisterPanel(callback) |
|
85 self.setHTML('<b>You are not identified, please log in</b>') |
|
86 self.setWidget(_form) |