[Mpuls-commits] r1335 - wasko/branches/2.0/mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Feb 8 17:19:54 CET 2010
Author: torsten
Date: 2010-02-08 17:19:53 +0100 (Mon, 08 Feb 2010)
New Revision: 1335
Added:
wasko/branches/2.0/mpulsweb/lib/validators.py
Log:
* mpulsweb/lib/validators.py: New. Copied BaseFormValidator,
SecurePassword, NewPasswordForm from waskaweb.lib.validators.
Added: wasko/branches/2.0/mpulsweb/lib/validators.py
===================================================================
--- wasko/branches/2.0/mpulsweb/lib/validators.py 2010-02-08 16:07:09 UTC (rev 1334)
+++ wasko/branches/2.0/mpulsweb/lib/validators.py 2010-02-08 16:19:53 UTC (rev 1335)
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+
+import formencode
+import re
+
+class BaseFormValidator(formencode.Schema):
+ def __init__(self):
+ formencode.api.set_stdtranslation(domain="FormEncode", languages=["de"])
+
+ allow_extra_fields = True
+ filter_extra_fields = False
+
+class SecurePassword(formencode.validators.FancyValidator):
+
+ min = 8
+ non_letter = 2
+ non_letter_literal = "zwei"
+ letter_regex = re.compile(r'[a-zA-Z]')
+
+ messages = {
+ 'too_few': u'Ihr Passwort muss mindestens %(min)i '
+ u'Zeichen lang sein',
+ 'non_letter': u'Sie müssen mindestens %(non_letter)s '
+ u'Nicht-Buchstaben in Ihrem Passwort verwenden.',
+ 'only_ascii': u'Das Passwort darf nur aus ASCII-Zeichen bestehen.'
+ }
+
+ def _to_python(self, value, state):
+ # _to_python gets run before validate_python. Here we
+ # strip whitespace off the password, because leading and
+ # trailing whitespace in a password is too elite.
+ return value.strip()
+
+ def validate_python(self, value, state):
+ try:
+ unicode(str(value), "ascii")
+ except (UnicodeDecodeError, UnicodeEncodeError):
+ raise formencode.Invalid(self.message("only_ascii", state), value, state)
+ if len(value) < self.min:
+ raise formencode.Invalid(self.message("too_few", state, min=self.min), value, state)
+ non_letters = self.letter_regex.sub('', value)
+ if len(non_letters) < self.non_letter:
+ raise formencode.Invalid(self.message("non_letter", state, non_letter=self.non_letter_literal), value, state)
+
+class NewPasswordForm(BaseFormValidator):
+ passwd = SecurePassword()
+ passwd2 = formencode.validators.String()
+ chained_validators = [formencode.validators.FieldsMatch('passwd', 'passwd2')]
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8
More information about the Mpuls-commits
mailing list