Mercurial > kallithea
comparison rhodecode/model/validators.py @ 3914:424b6c711a7f beta
allow underscores in usernames. Helps creating special internal users
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 29 May 2013 12:13:02 +0200 |
parents | 2576a20d94ca |
children | 8ddf35e02d05 |
comparison
equal
deleted
inserted
replaced
3913:5f192af1ba21 | 3914:424b6c711a7f |
---|---|
86 'system_invalid_username': | 86 'system_invalid_username': |
87 _(u'Username "%(username)s" is forbidden'), | 87 _(u'Username "%(username)s" is forbidden'), |
88 'invalid_username': | 88 'invalid_username': |
89 _(u'Username may only contain alphanumeric characters ' | 89 _(u'Username may only contain alphanumeric characters ' |
90 'underscores, periods or dashes and must begin with ' | 90 'underscores, periods or dashes and must begin with ' |
91 'alphanumeric character') | 91 'alphanumeric character or underscore') |
92 } | 92 } |
93 | 93 |
94 def validate_python(self, value, state): | 94 def validate_python(self, value, state): |
95 if value in ['default', 'new_user']: | 95 if value in ['default', 'new_user']: |
96 msg = M(self, 'system_invalid_username', state, username=value) | 96 msg = M(self, 'system_invalid_username', state, username=value) |
103 if old_un != value or not edit: | 103 if old_un != value or not edit: |
104 if User.get_by_username(value, case_insensitive=True): | 104 if User.get_by_username(value, case_insensitive=True): |
105 msg = M(self, 'username_exists', state, username=value) | 105 msg = M(self, 'username_exists', state, username=value) |
106 raise formencode.Invalid(msg, value, state) | 106 raise formencode.Invalid(msg, value, state) |
107 | 107 |
108 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]*$', value) is None: | 108 if re.match(r'^[a-zA-Z0-9\_]{1}[a-zA-Z0-9\-\_\.]*$', value) is None: |
109 msg = M(self, 'invalid_username', state) | 109 msg = M(self, 'invalid_username', state) |
110 raise formencode.Invalid(msg, value, state) | 110 raise formencode.Invalid(msg, value, state) |
111 return _validator | 111 return _validator |
112 | 112 |
113 | 113 |