changeset 2302:1f449e482bcc

allow auth methods to set the login hint below the input fields
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 10 Jul 2007 19:31:27 +0200
parents 35617ed953c4
children 4f73af30fd75 39691c426192
files MoinMoin/auth/__init__.py MoinMoin/auth/openidrp.py MoinMoin/userform/login.py
diffstat 3 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/auth/__init__.py	Tue Jul 10 19:13:03 2007 +0200
+++ b/MoinMoin/auth/__init__.py	Tue Jul 10 19:31:27 2007 +0200
@@ -3,10 +3,11 @@
     MoinMoin - modular authentication handling
 
     Each authentication method is an object instance containing
-    three methods:
+    four methods:
       * login(request, user_obj, **kw)
       * logout(request, user_obj, **kw)
       * request(request, user_obj, **kw)
+      * login_hint(request)
 
     The kw arguments that are passed in are currently:
        attended: boolean indicating whether a user (attended=True) or
@@ -23,6 +24,10 @@
        openid_identifier: the OpenID identifier we got from the form
                           (or None) [login only]
 
+    login_hint() should return a HTML text that is displayed to the user right
+    below the login form, it should tell the user what to do in case of a
+    forgotten password and how to create an account (if applicable.)
+
     More may be added.
 
     The request method is called for each request except login/logout.
@@ -187,6 +192,8 @@
         if self.name and user_obj and user_obj.auth_method == self.name:
             user_obj.valid = False
         return user_obj, True
+    def login_hint(self, request):
+        return None
 
 class MoinLogin(BaseAuth):
     """ handle login from moin login form """
@@ -225,3 +232,12 @@
         else:
             if verbose: request.log("moin_login not valid, previous valid=%d." % user_obj.valid)
             return ContinueLogin(user_obj, _("Invalid username or password."))
+
+    def login_hint(self, request):
+        _ = request.getText
+        userprefslink = request.page.url(request, querystr={'action': 'newaccount'})
+        sendmypasswordlink = request.page.url(request, querystr={'action': 'recoverpass'})
+        return _('If you do not have an account, <a href="%(userprefslink)s">you can create one now</a>. '
+                 '<a href="%(sendmypasswordlink)s">Forgot your password?</a>', formatted=False) % {
+               'userprefslink': userprefslink,
+               'sendmypasswordlink': sendmypasswordlink}
--- a/MoinMoin/auth/openidrp.py	Tue Jul 10 19:13:03 2007 +0200
+++ b/MoinMoin/auth/openidrp.py	Tue Jul 10 19:31:27 2007 +0200
@@ -233,3 +233,8 @@
                     self._openid_form(request, form, form_html)
                 ret = MultistageFormLogin(mcall)
                 return ret
+
+    def login_hint(self, request):
+        _ = request.getText
+        return _("If you do not have an account yet, you can still log in "
+                 "with your OpenID and create one during login.")
--- a/MoinMoin/userform/login.py	Tue Jul 10 19:13:03 2007 +0200
+++ b/MoinMoin/userform/login.py	Tue Jul 10 19:31:27 2007 +0200
@@ -37,12 +37,11 @@
         sn = request.getScriptname()
         pi = request.getPathinfo()
         action = u"%s%s" % (sn, pi)
-        userprefslink = request.page.url(request, querystr={'action': 'newaccount'})
-        sendmypasswordlink = request.page.url(request, querystr={'action': 'recoverpass'})
-        hint = _('If you do not have an account, <a href="%(userprefslink)s">you can create one now</a>. '
-                 '<a href="%(sendmypasswordlink)s">Forgot your password?</a>', formatted=False) % {
-                 'userprefslink': userprefslink,
-                 'sendmypasswordlink': sendmypasswordlink}
+        hints = []
+        for authm in request.cfg.auth:
+            hint = authm.login_hint(request)
+            if hint:
+                hints.append(hint)
         self._form = html.FORM(action=action, name="loginform")
         self._table = html.TABLE(border="0")
 
@@ -52,7 +51,8 @@
 
         self._form.append(html.INPUT(type="hidden", name="action", value="login"))
         self._form.append(self._table)
-        self._form.append(html.P().append(html.Raw(hint)))
+        for hint in hints:
+            self._form.append(html.P().append(html.Raw(hint)))
         self._form.append(html.Raw("</div>"))
 
         cfg = request.cfg