Changeset - 029e69f0d21d
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 15 years ago 2011-01-26 17:38:08
marcin@python-works.com
fixed #102 allowed '.' character in username
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/forms.py
Show inline comments
 
@@ -57,52 +57,52 @@ class ValidAuthToken(formencode.validato
 
    def validate_python(self, value, state):
 

	
 
        if value != authentication_token():
 
            raise formencode.Invalid(self.message('invalid_token', state,
 
                                            search_number=value), value, state)
 

	
 
def ValidUsername(edit, old_data):
 
    class _ValidUsername(formencode.validators.FancyValidator):
 

	
 
        def validate_python(self, value, state):
 
            if value in ['default', 'new_user']:
 
                raise formencode.Invalid(_('Invalid username'), value, state)
 
            #check if user is unique
 
            old_un = None
 
            if edit:
 
                old_un = UserModel().get(old_data.get('user_id')).username
 

	
 
            if old_un != value or not edit:
 
                if UserModel().get_by_username(value, cache=False,
 
                                               case_insensitive=True):
 
                    raise formencode.Invalid(_('This username already exists') ,
 
                                             value, state)
 

	
 

	
 
            if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_]+$', value) is None:
 
            if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None:
 
                raise formencode.Invalid(_('Username may only contain '
 
                                           'alphanumeric characters underscores '
 
                                           'or dashes and must begin with '
 
                                           'alphanumeric characters underscores, '
 
                                           'periods or dashes and must begin with '
 
                                           'alphanumeric character'),
 
                                      value, state)
 

	
 

	
 

	
 
    return _ValidUsername
 

	
 

	
 

	
 
def ValidUsersGroup(edit, old_data):
 

	
 
    class _ValidUsersGroup(formencode.validators.FancyValidator):
 

	
 
        def validate_python(self, value, state):
 
            if value in ['default']:
 
                raise formencode.Invalid(_('Invalid group name'), value, state)
 
            #check if group is unique
 
            old_un = None
 
            if edit:
 
                old_un = UserModel().get(old_data.get('users_group_id')).username
 

	
 
            if old_un != value or not edit:
 
                if UsersGroupModel().get_by_groupname(value, cache=False,
 
                                               case_insensitive=True):
0 comments (0 inline, 0 general)