comparison rhodecode/model/forms.py @ 745:c366b237c91d beta

added test for username and email case senstitive validators, fixed valid username to take underscores
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 23 Nov 2010 22:31:08 +0100
parents c9fa3f53143b
children 18a3ca35d501
comparison
equal deleted inserted replaced
744:3389f272ece1 745:c366b237c91d
70 if old_un != value or not edit: 70 if old_un != value or not edit:
71 if UserModel().get_by_username(value, cache=False, 71 if UserModel().get_by_username(value, cache=False,
72 case_insensitive=True): 72 case_insensitive=True):
73 raise formencode.Invalid(_('This username already exists') , 73 raise formencode.Invalid(_('This username already exists') ,
74 value, state) 74 value, state)
75 75
76 76
77 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-]+$', value) is None: 77 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_]+$', value) is None:
78 raise formencode.Invalid(_('Username may only contain ' 78 raise formencode.Invalid(_('Username may only contain '
79 'alphanumeric characters ' 79 'alphanumeric characters underscores '
80 'or dashes and cannot begin with a dash'), 80 'or dashes and must begin with '
81 'alphanumeric character'),
81 value, state) 82 value, state)
82 83
83 84
84 85
85 return _ValidUsername 86 return _ValidUsername
86 87
87 class ValidPassword(formencode.validators.FancyValidator): 88 class ValidPassword(formencode.validators.FancyValidator):
88 89
89 def to_python(self, value, state): 90 def to_python(self, value, state):
256 257
257 def UniqSystemEmail(old_data): 258 def UniqSystemEmail(old_data):
258 class _UniqSystemEmail(formencode.validators.FancyValidator): 259 class _UniqSystemEmail(formencode.validators.FancyValidator):
259 def to_python(self, value, state): 260 def to_python(self, value, state):
260 value = value.lower() 261 value = value.lower()
261 #TODO:write test for MixedCase scenarios
262 if old_data.get('email') != value: 262 if old_data.get('email') != value:
263 sa = meta.Session() 263 sa = meta.Session()
264 try: 264 try:
265 user = sa.query(User).filter(User.email == value).scalar() 265 user = sa.query(User).filter(User.email == value).scalar()
266 if user: 266 if user: