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") |
42
|
51 self.loginBox.setText("goffi_local") |
0
|
52 self.passBox = PasswordTextBox() |
|
53 self.passBox.setName("password") |
42
|
54 self.passBox.setText("toto") |
0
|
55 grid = Grid(2, 2) |
|
56 grid.setText(0,0,"Login:") |
|
57 grid.setWidget(0,1, self.loginBox) |
|
58 grid.setText(1,0, "Password:") |
|
59 grid.setWidget(1,1, self.passBox) |
|
60 vPanel.add(grid) |
|
61 login_but = Button("Login", getattr(self, "onLogin")) |
|
62 vPanel.add(login_but) |
|
63 self.add(vPanel) |
|
64 self.addFormHandler(self) |
|
65 self.setAction('register_api/login') |
|
66 |
|
67 def onLogin(self): |
|
68 self.submit() |
|
69 |
|
70 def onSubmit(self, event): |
|
71 pass |
|
72 |
|
73 def onSubmitComplete(self, event): |
|
74 result = event.getResults() |
|
75 if result == "AUTH ERROR": |
|
76 Window.alert('You login and/or password is incorrect. Please try again') |
|
77 elif result == "LOGGED": |
|
78 self.callback() |
|
79 else: |
|
80 Window.alert('Submit error: %s' % result) |
|
81 |
|
82 class RegisterBox(DialogBox): |
|
83 |
|
84 def __init__(self, callback, *args,**kwargs): |
|
85 DialogBox.__init__(self,*args,**kwargs) |
|
86 _form = RegisterPanel(callback) |
|
87 self.setHTML('<b>You are not identified, please log in</b>') |
|
88 self.setWidget(_form) |