diff 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
line wrap: on
line diff
--- a/browser_side/register.py	Wed May 25 15:45:16 2011 +0200
+++ b/browser_side/register.py	Thu May 26 16:43:30 2011 +0200
@@ -28,9 +28,12 @@
 from pyjamas.ui.TextBox import TextBox
 from pyjamas.ui.FormPanel import FormPanel
 from pyjamas.ui.Button import Button
+from pyjamas.ui.Label import Label
+from pyjamas.ui.CheckBox import CheckBox
 from pyjamas.ui.DialogBox import DialogBox
 from pyjamas import Window
 from pyjamas.ui import HasAlignment
+import re
 
 
 
@@ -46,24 +49,89 @@
         self.setMethod(FormPanel.METHOD_POST)
         vPanel = VerticalPanel()
         vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
-        self.loginBox = TextBox()
-        self.loginBox.setName("login")
-        self.passBox = PasswordTextBox()
-        self.passBox.setName("password")
-        grid = Grid(2, 2)
-        grid.setText(0,0,"Login:")
-        grid.setWidget(0,1, self.loginBox)
-        grid.setText(1,0, "Password:")
-        grid.setWidget(1,1, self.passBox)
-        vPanel.add(grid)
-        login_but = Button("Login", getattr(self, "onLogin"))
-        vPanel.add(login_but)
+        self.warning_msg = Label()
+        self.warning_msg.setVisible(False)
+        self.warning_msg.setStyleName('formWarning')
+        vPanel.add(self.warning_msg)
+
+        self.login_box = TextBox()
+        self.login_box.setName("login")
+        self.pass_box = PasswordTextBox()
+        self.pass_box.setName("password")
+        login_grid = Grid(2, 2)
+        login_grid.setText(0,0,"Login:")
+        login_grid.setWidget(0,1, self.login_box)
+        login_grid.setText(1,0, "Password:")
+        login_grid.setWidget(1,1, self.pass_box)
+        vPanel.add(login_grid)
+        
+        self.new_account = CheckBox('Register new account')
+        self.new_account.setName('new_account')
+        self.new_account.addClickListener(self.onNewAccountChecked)
+        vPanel.add(self.new_account)
+        
+        
+        self.email_box = TextBox()
+        self.email_box.setName("email")
+        self.register_grid = Grid(1, 2)
+        self.register_grid.setText(0,0,"email:")
+        self.register_grid.setWidget(0,1, self.email_box)
+        self.register_grid.setVisible(False)
+        vPanel.add(self.register_grid)
+        self.info_register_lb = Label('Your password will be sent to the given email')
+        self.info_register_lb.setVisible(False)
+        vPanel.add(self.register_grid)
+        vPanel.add(self.info_register_lb)
+        
+        self.login_but = Button("Login", getattr(self, "onLogin"))
+        vPanel.add(self.login_but)
+        self.register_but = Button("Register", getattr(self, "onRegister"))
+        self.register_but.setVisible(False)
+        vPanel.add(self.register_but)
         self.add(vPanel)
         self.addFormHandler(self)
         self.setAction('register_api/login')
 
+    def changeMode(self, mode):
+        """Change the configuration of the dialog
+        @param mode: "login" or "register"""
+        if mode == "register":
+            self.pass_box.setEnabled(False)
+            self.register_grid.setVisible(True)
+            self.info_register_lb.setVisible(True)
+            self.login_but.setVisible(False)
+            self.register_but.setVisible(True)
+            self.new_account.setChecked(True)
+        else:
+            self.pass_box.setEnabled(True)
+            self.register_grid.setVisible(False)
+            self.info_register_lb.setVisible(False)
+            self.login_but.setVisible(True)
+            self.register_but.setVisible(False)
+            self.new_account.setChecked(False)
+
+
+    def onNewAccountChecked(self, sender):
+        if sender.isChecked():
+            self.changeMode("register")
+        else:
+            self.changeMode("login")
+
     def onLogin(self):
         self.submit()
+
+    def onRegister(self):
+        print self.login_box.getText()
+        if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE):
+            self.warning_msg.setText('Invaling login, valid characters are a-z A-Z 0-9 _ -')
+            self.warning_msg.setVisible(True)
+        elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE):
+            self.warning_msg.setText('Invaling email address')
+            self.warning_msg.setVisible(True)
+        else:
+            self.warning_msg.setVisible(False)
+            self.submit()
+
     
     def onSubmit(self, event):
         pass
@@ -74,6 +142,14 @@
             Window.alert('You login and/or password is incorrect. Please try again')
         elif result == "LOGGED":
             self.callback()
+        elif result == "ALREADY EXISTS":
+            self.warning_msg.setText('This login already exists, please choose an other one')
+            self.warning_msg.setVisible(True)
+        elif result == "REGISTRATION":
+            self.warning_msg.setVisible(False)
+            self.changeMode('login')
+            self.pass_box.setText('')
+            Window.alert('An email has been sent to you with your login informations\nPlease remember that this is ONLY A TECHNICAL DEMO')
         else:
             Window.alert('Submit error: %s' % result)