diff src/browser/sat_browser/register.py @ 871:54f6c5b86a87

server, browser: new "allow_registration" option to enable/disable new account registration through Liberia interface
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 12:40:14 +0100
parents 77a494f13118
children 0d719b6a4115
line wrap: on
line diff
--- a/src/browser/sat_browser/register.py	Mon Feb 29 12:37:58 2016 +0100
+++ b/src/browser/sat_browser/register.py	Mon Feb 29 12:40:14 2016 +0100
@@ -48,9 +48,10 @@
 
 class RegisterPanel(FormPanel):
 
-    def __init__(self, callback):
+    def __init__(self, callback, session_data):
         """
-        @param callback: method to call if login successful
+        @param callback(callable): method to call if login successful
+        @param session_data(dict): session metadata
         """
         FormPanel.__init__(self)
         self.setSize('600px', '350px')
@@ -93,50 +94,51 @@
         login_but.setStyleName('button')
         login_but.addStyleName('red')
         login_vpanel.add(login_but)
+        self.right_side.add(login_stack, 'Return to the login screen')
 
         #The hidden submit_type field
         self.submit_type = Hidden('submit_type')
         login_vpanel.add(self.submit_type)
 
         ##Register stack##
-        register_stack = SimplePanel()
-        register_stack.setStyleName('registerPanel_content')
-        register_vpanel = VerticalPanel()
-        register_stack.setWidget(register_vpanel)
+        if session_data["allow_registration"]:
+            register_stack = SimplePanel()
+            register_stack.setStyleName('registerPanel_content')
+            register_vpanel = VerticalPanel()
+            register_stack.setWidget(register_vpanel)
 
-        self.register_warning_msg = HTML('')
-        self.register_warning_msg.setStyleName('formWarning')
-        register_vpanel.add(self.register_warning_msg)
+            self.register_warning_msg = HTML('')
+            self.register_warning_msg.setStyleName('formWarning')
+            register_vpanel.add(self.register_warning_msg)
 
-        register_login_label = Label('Login:')
-        self.register_login_box = TextBox()
-        self.register_login_box.setName("register_login")
-        self.register_login_box.addKeyboardListener(self)
-        email_label = Label('E-mail:')
-        self.email_box = TextBox()
-        self.email_box.setName("email")
-        self.email_box.addKeyboardListener(self)
-        register_pass_label = Label('Password:')
-        self.register_pass_box = PasswordTextBox()
-        self.register_pass_box.setName("register_password")
-        self.register_pass_box.addKeyboardListener(self)
-        register_vpanel.add(register_login_label)
-        register_vpanel.add(self.register_login_box)
-        register_vpanel.add(email_label)
-        register_vpanel.add(self.email_box)
-        register_vpanel.add(register_pass_label)
-        register_vpanel.add(self.register_pass_box)
+            register_login_label = Label('Login:')
+            self.register_login_box = TextBox()
+            self.register_login_box.setName("register_login")
+            self.register_login_box.addKeyboardListener(self)
+            email_label = Label('E-mail:')
+            self.email_box = TextBox()
+            self.email_box.setName("email")
+            self.email_box.addKeyboardListener(self)
+            register_pass_label = Label('Password:')
+            self.register_pass_box = PasswordTextBox()
+            self.register_pass_box.setName("register_password")
+            self.register_pass_box.addKeyboardListener(self)
+            register_vpanel.add(register_login_label)
+            register_vpanel.add(self.register_login_box)
+            register_vpanel.add(email_label)
+            register_vpanel.add(self.email_box)
+            register_vpanel.add(register_pass_label)
+            register_vpanel.add(self.register_pass_box)
 
-        register_but = Button("Register a new account", getattr(self, "onRegister"))
-        register_but.setStyleName('button')
-        register_but.addStyleName('red')
-        register_vpanel.add(register_but)
+            register_but = Button("Register a new account", getattr(self, "onRegister"))
+            register_but.setStyleName('button')
+            register_but.addStyleName('red')
+            register_vpanel.add(register_but)
 
-        self.right_side.add(login_stack, 'Return to the login screen')
-        self.right_side.add(register_stack, 'No account yet? Create a new one!')
-        self.right_side.addStackChangeListener(self)
+            self.right_side.add(register_stack, 'No account yet? Create a new one!')
+            self.right_side.addStackChangeListener(self)
+            register_stack.setWidth(None)
         login_stack.setWidth(None)
-        register_stack.setWidth(None)
 
         self.add(main_panel)
         self.addFormHandler(self)
@@ -268,9 +270,9 @@
 
 class RegisterBox(PopupPanel):
 
-    def __init__(self, callback, *args, **kwargs):
+    def __init__(self, callback, session_data, *args, **kwargs):
         PopupPanel.__init__(self, *args, **kwargs)
-        self._form = RegisterPanel(callback)
+        self._form = RegisterPanel(callback, session_data)
         self.setWidget(self._form)
 
     def onWindowResized(self, width, height):