changeset 4879:c19a628febc1

Updated user forms and prefs to simplify logging in with OpenID and prepare for disabling certain preferences available via SREG.
author Rowan Kerr <rowan@stasis.org>
date Fri, 15 May 2009 17:18:45 -0400
parents dffe83c636a7
children 7ac56b991253
files MoinMoin/userform/login.py MoinMoin/userprefs/prefs.py
diffstat 2 files changed, 40 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/userform/login.py	Fri May 15 14:17:23 2009 -0400
+++ b/MoinMoin/userform/login.py	Fri May 15 17:18:45 2009 -0400
@@ -39,7 +39,7 @@
             hint = authm.login_hint(request)
             if hint:
                 hints.append(hint)
-        self._form = html.FORM(action=action, name="loginform")
+        self._form = html.FORM(action=action, name="loginform", id="loginform")
         self._table = html.TABLE(border="0")
 
         # Use the user interface language and direction
@@ -67,20 +67,49 @@
                 ),
             ])
 
+        # Restrict type of input available for OpenID input
+        # based on wiki configuration.
         if 'openid_identifier' in cfg.auth_login_inputs:
-            self.make_row(_('OpenID'), [
-                html.INPUT(
-                    type="text", size="32", name="openid_identifier",
-                    id="openididentifier"
-                ),
-            ])
+            if len(cfg.openidrp_allowed_op) == 1:
+                self.make_row(_('OpenID'), [
+                     html.INPUT(
+                         type="hidden", name="openid_identifier",
+                         value=cfg.openidrp_allowed_op[0]
+                     ),
+                ])
+            elif len(cfg.openidrp_allowed_op) > 1:
+                op_select = html.SELECT(name="openid_identifier",
+                    id="openididentifier")
+                for op_uri in cfg.openidrp_allowed_op:
+                    op_select.append(html.OPTION(value=op_uri).append(
+                        html.Raw(op_uri)))
 
+                self.make_row(_('OpenID'), [op_select,])
+            else:
+                self.make_row(_('OpenID'), [
+                    html.INPUT(
+                        type="text", size="32", name="openid_identifier",
+                        id="openididentifier"
+                    ),
+                ])
+
+        # Need both hidden field and submit values for auto-submit to work
         self.make_row('', [
+            html.INPUT(type="hidden", name="login", value=_('Login')),
             html.INPUT(
                 type="submit", name='login', value=_('Login')
             ),
         ])
 
+        # Automatically submit the form if only a single OpenID Provider is allowed
+        if 'openid_identifier' in cfg.auth_login_inputs and len(cfg.openidrp_allowed_op) == 1:
+            self._form.append("""<script type="text/javascript">
+<!--//
+document.getElementById("loginform").submit();
+//-->
+</script>
+""")
+
         return unicode(self._form)
 
 def getLogin(request):
--- a/MoinMoin/userprefs/prefs.py	Fri May 15 14:17:23 2009 -0400
+++ b/MoinMoin/userprefs/prefs.py	Fri May 15 17:18:45 2009 -0400
@@ -239,7 +239,7 @@
         'rfc': '%a %b %d %H:%M:%S %Y & %a %b %d %Y',
     }
 
-    def _tz_select(self):
+    def _tz_select(self, enabled=True):
         """ Create time zone selection. """
         tz = 0
         if self.request.user.valid:
@@ -261,7 +261,7 @@
                 ),
             ))
 
-        return util.web.makeSelection('tz_offset', options, str(tz))
+        return util.web.makeSelection('tz_offset', options, str(tz), 1, False, enabled)
 
 
     def _dtfmt_select(self):
@@ -279,7 +279,7 @@
         return util.web.makeSelection('datetime_fmt', options, selected)
 
 
-    def _lang_select(self):
+    def _lang_select(self, enabled=True):
         """ Create language selection. """
         from MoinMoin import i18n
         _ = self._
@@ -291,7 +291,7 @@
             name = lang[1]['x-language']
             options.append((lang[0], name))
 
-        return util.web.makeSelection('language', options, cur_lang)
+        return util.web.makeSelection('language', options, cur_lang, 1, False, enabled)
 
     def _theme_select(self):
         """ Create theme selection. """