changeset 4336:4f3d0b92d1c9

add i18n to the password checker result messages, add request param
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 25 Sep 2008 18:31:24 +0200
parents 99ed52b53e4e
children 79f0ef6935b9
files MoinMoin/action/newaccount.py MoinMoin/action/recoverpass.py MoinMoin/config/_tests/test_multiconfig.py MoinMoin/config/multiconfig.py MoinMoin/userprefs/changepass.py
diffstat 5 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/newaccount.py	Tue Sep 23 00:44:45 2008 +0200
+++ b/MoinMoin/action/newaccount.py	Thu Sep 25 18:31:24 2008 +0200
@@ -56,7 +56,7 @@
 
     pw_checker = request.cfg.password_checker
     if pw_checker:
-        pw_error = pw_checker(theuser.name, password)
+        pw_error = pw_checker(request, theuser.name, password)
         if pw_error:
             return _("Password not acceptable: %s") % pw_error
 
--- a/MoinMoin/action/recoverpass.py	Tue Sep 23 00:44:45 2008 +0200
+++ b/MoinMoin/action/recoverpass.py	Thu Sep 25 18:31:24 2008 +0200
@@ -173,7 +173,7 @@
             pw_checker = request.cfg.password_checker
             pw_error = None
             if pw_checker:
-                pw_error = pw_checker(name, newpass)
+                pw_error = pw_checker(request, name, newpass)
                 if pw_error:
                     msg = _("Password not acceptable: %s") % pw_error
             if not pw_error:
--- a/MoinMoin/config/_tests/test_multiconfig.py	Tue Sep 23 00:44:45 2008 +0200
+++ b/MoinMoin/config/_tests/test_multiconfig.py	Thu Sep 25 18:31:24 2008 +0200
@@ -32,7 +32,7 @@
             py.test.skip("password_checker is disabled in the configuration, not testing it")
         else:
             for pw, result in self.tests_builtin:
-                pw_error = pw_checker(self.username, pw)
+                pw_error = pw_checker(self.request, self.username, pw)
                 print "%r: %s" % (pw, pw_error)
                 assert result == (pw_error is None)
 
--- a/MoinMoin/config/multiconfig.py	Tue Sep 23 00:44:45 2008 +0200
+++ b/MoinMoin/config/multiconfig.py	Thu Sep 25 18:31:24 2008 +0200
@@ -638,7 +638,7 @@
     # the options dictionary.
 
 
-def _default_password_checker(request, username, password):
+def _default_password_checker(cfg, request, username, password):
     """ Check if a password is secure enough.
         We use a built-in check to get rid of the worst passwords.
 
@@ -650,18 +650,19 @@
         @return: None if there is no problem with the password,
                  some string with an error msg, if the password is problematic.
     """
+    _ = request.getText
     try:
         # in any case, do a very simple built-in check to avoid the worst passwords
         if len(password) < 6:
-            raise ValueError("Password too short.")
+            raise ValueError(_("Password is too short."))
         if len(set(password)) < 4:
-            raise ValueError("Password has not enough different characters.")
+            raise ValueError(_("Password has not enough different characters."))
 
         username_lower = username.lower()
         password_lower = password.lower()
         if username in password or password in username or \
            username_lower in password_lower or password_lower in username_lower:
-            raise ValueError("Password too easy (containment).")
+            raise ValueError(_("Password is too easy (password contains name or name contains password)."))
 
         keyboards = (ur"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./", # US kbd
                      ur"^1234567890ß´qwertzuiopü+asdfghjklöä#yxcvbnm,.-", # german kbd
@@ -670,10 +671,10 @@
             rev_kbd = kbd[::-1]
             if password in kbd or password in rev_kbd or \
                password_lower in kbd or password_lower in rev_kbd:
-                raise ValueError("Password too easy (kbd sequence)")
+                raise ValueError(_("Password is too easy (keyboard sequence)."))
         return None
     except ValueError, err:
-        return str(err)
+        return unicode(err)
 
 
 class DefaultExpression(object):
--- a/MoinMoin/userprefs/changepass.py	Tue Sep 23 00:44:45 2008 +0200
+++ b/MoinMoin/userprefs/changepass.py	Thu Sep 25 18:31:24 2008 +0200
@@ -54,7 +54,7 @@
 
         pw_checker = request.cfg.password_checker
         if pw_checker:
-            pw_error = pw_checker(request.user.name, password)
+            pw_error = pw_checker(request, request.user.name, password)
             if pw_error:
                 return 'error', _("Password not acceptable: %s") % pw_error