diff options
author | Boris Bobrov <breton@cynicmansion.ru> | 2016-07-25 03:23:25 +0300 |
---|---|---|
committer | Boris Bobrov <breton@cynicmansion.ru> | 2016-07-25 03:23:25 +0300 |
commit | 1aab84d0dcf369c3098d752cf19a19abda0b833d (patch) | |
tree | da6ab82bfcb301c19c4cdb6b2d46f1e31d492afb /mediagoblin/auth/tools.py | |
parent | c49e5162ca8e357be38018d045554ccb38f99b10 (diff) | |
parent | 4106eef3a4e8764a1a89956046b01ebacec017a9 (diff) | |
download | mediagoblin-1aab84d0dcf369c3098d752cf19a19abda0b833d.tar.lz mediagoblin-1aab84d0dcf369c3098d752cf19a19abda0b833d.tar.xz mediagoblin-1aab84d0dcf369c3098d752cf19a19abda0b833d.zip |
Merge branch 'login-validator-5414'
Diffstat (limited to 'mediagoblin/auth/tools.py')
-rw-r--r-- | mediagoblin/auth/tools.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py index 9c16a980..ae6fadf6 100644 --- a/mediagoblin/auth/tools.py +++ b/mediagoblin/auth/tools.py @@ -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 |