No length check for login form
authorJonathan Sandoval <jsandoval@utp.edu.co>
Thu, 7 Apr 2016 21:34:00 +0000 (16:34 -0500)
committerJonathan Sandoval <jsandoval@utp.edu.co>
Thu, 7 Apr 2016 21:34:00 +0000 (16:34 -0500)
mediagoblin/auth/tools.py
mediagoblin/plugins/basic_auth/forms.py

index 9c16a980d7ee54d4bc1b861a8697897cbbbd8435..ae6fadf618c35ad86977e1da1cbf37a2350d55b5 100644 (file)
@@ -34,14 +34,19 @@ from mediagoblin import auth
 _log = logging.getLogger(__name__)
 
 
-def normalize_user_or_email_field(allow_email=True, allow_user=True):
-    """
-    Check if we were passed a field that matches a username and/or email
+def normalize_user_or_email_field(allow_email=True, allow_user=True,
+                                  is_login=False):
+    """Check if we were passed a field that matches a username and/or email
     pattern.
 
     This is useful for fields that can take either a username or email
-    address. Use the parameters if you want to only allow a username for
-    instance"""
+    address. Use the parameters if you want to only allow a username
+    for instance
+
+    is_login : bool
+        If is_login is True, does not check the length of username.
+
+    """
     message = _(u'Invalid User name or email address.')
     nomail_msg = _(u"This field does not take email addresses.")
     nouser_msg = _(u"This field requires an email address.")
@@ -56,7 +61,8 @@ def normalize_user_or_email_field(allow_email=True, allow_user=True):
         else:  # lower case user names
             if not allow_user:
                 raise wtforms.ValidationError(nouser_msg)
-            wtforms.validators.Length(min=3, max=30)(form, field)
+            if not is_login:
+                wtforms.validators.Length(min=3, max=30)(form, field)
             wtforms.validators.Regexp(r'^[-_\w]+$')(form, field)
             field.data = field.data.lower()
         if field.data is None:  # should not happen, but be cautious anyway
index 9a6db226b2b32be64cd730347fbd61582c061b24..3d684e91b18fbcf81464771bec81f270dd3f164c 100644 (file)
@@ -38,7 +38,7 @@ class LoginForm(wtforms.Form):
     username = wtforms.StringField(
         _('Username or Email'),
         [wtforms.validators.InputRequired(),
-         normalize_user_or_email_field()])
+         normalize_user_or_email_field(is_login=True)])
     password = wtforms.PasswordField(
         _('Password'))
     stay_logged_in = wtforms.BooleanField(