changeset 445:c0ff91cabea0

server_side, browser_side: new account password must contain at least 6 chars + cosmetic change for register warning message
author souliane <souliane@mailoo.org>
date Wed, 07 May 2014 19:29:10 +0200
parents b64e528fb524
children c406e46fe9c0
files browser_side/register.py constants.py libervia_server/__init__.py
diffstat 3 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/register.py	Thu May 15 20:27:52 2014 +0200
+++ b/browser_side/register.py	Wed May 07 19:29:10 2014 +0200
@@ -21,6 +21,8 @@
 #This page manage subscription and new account creation
 import pyjd # this is dummy in pyjs
 
+from constants import Const as C
+from sat.core.i18n import _
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
@@ -31,6 +33,7 @@
 from pyjamas.ui.FormPanel import FormPanel
 from pyjamas.ui.Button import Button
 from pyjamas.ui.Label import Label
+from pyjamas.ui.HTML import HTML
 from pyjamas.ui.PopupPanel import PopupPanel
 from pyjamas.ui.Image import Image
 from pyjamas.ui.Hidden import Hidden
@@ -102,7 +105,7 @@
         register_vpanel = VerticalPanel()
         register_tab.setWidget(register_vpanel)
 
-        self.register_warning_msg = Label('')
+        self.register_warning_msg = HTML('')
         self.register_warning_msg.setVisible(False)
         self.register_warning_msg.setStyleName('formWarning')
         register_vpanel.add(self.register_warning_msg)
@@ -175,7 +178,7 @@
         pass
 
     def onLogin(self, button):
-        if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE):
+        if not re.match(r'^[a-z0-9_-]+$', self.login_box.getText(), re.IGNORECASE):
             self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -')
             self.login_warning_msg.setVisible(True)
         else:
@@ -183,11 +186,14 @@
             self.submit()
 
     def onRegister(self, button):
-        if not re.match(r'^[a-z0-9_-]+$',self.register_login_box.getText(), re.IGNORECASE):
-            self.register_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -')
+        if not re.match(r'^[a-z0-9_-]+$', self.register_login_box.getText(), re.IGNORECASE):
+            self.register_warning_msg.setHTML(_('Invalid login, valid characters<br>are a-z A-Z 0-9 _ -'))
             self.register_warning_msg.setVisible(True)
         elif not re.match(r'^.+@.+\..+', self.email_box.getText(), re.IGNORECASE):
-            self.register_warning_msg.setText('Invalid email address')
+            self.register_warning_msg.setHTML(_('Invalid email address'))
+            self.register_warning_msg.setVisible(True)
+        elif len(self.register_pass_box.getText()) < C.PASSWORD_MIN_LENGTH:
+            self.register_warning_msg.setHTML(_('Your password must contain<br>at least %d characters') % C.PASSWORD_MIN_LENGTH)
             self.register_warning_msg.setVisible(True)
         else:
             self.register_warning_msg.setVisible(False)
@@ -206,15 +212,16 @@
         elif result == "SESSION_ACTIVE":
             Window.alert('Session already active, this should not happen, please contact the author to fix it')
         elif result == "ALREADY EXISTS":
-            self.register_warning_msg.setText('This login already exists, please choose an other one')
+            self.register_warning_msg.setHTML('This login already exists,<br>please choose another one')
             self.register_warning_msg.setVisible(True)
         elif result == "INTERNAL":
-            self.register_warning_msg.setText('SERVER ERROR: something went wrong during registration process, please contact the server administrator')
+            self.register_warning_msg.setHTML('SERVER ERROR: something went wrong during registration process, please contact the server administrator')
             self.register_warning_msg.setVisible(True)
         elif result == "REGISTRATION":
             self.login_warning_msg.setVisible(False)
             self.register_warning_msg.setVisible(False)
             self.login_box.setText(self.register_login_box.getText())
+            self.login_pass_box.setText('')
             self.register_login_box.setText('')
             self.register_pass_box.setText('')
             self.email_box.setText('')
--- a/constants.py	Thu May 15 20:27:52 2014 +0200
+++ b/constants.py	Wed May 07 19:29:10 2014 +0200
@@ -44,4 +44,7 @@
     # Frontend parameters
     ENABLE_UNIBOX_KEY = D_("Composition")
     ENABLE_UNIBOX_PARAM = D_("Enable unibox")
+
+    # MISC
+    PASSWORD_MIN_LENGTH = 6  # for new account creation
     LOG_OPT_SECTION = APP_NAME.lower()
--- a/libervia_server/__init__.py	Thu May 15 20:27:52 2014 +0200
+++ b/libervia_server/__init__.py	Wed May 07 19:29:10 2014 +0200
@@ -654,7 +654,8 @@
         except KeyError:
             return "BAD REQUEST"
         if not re.match(r'^[a-z0-9_-]+$', login, re.IGNORECASE) or \
-           not re.match(r'^.+@.+\..+', email, re.IGNORECASE):
+           not re.match(r'^.+@.+\..+', email, re.IGNORECASE) or \
+           len(password) < C.PASSWORD_MIN_LENGTH:
             return "BAD REQUEST"
 
         def registered(result):