annotate register.py @ 7:7acca1ce1ca4

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