Changeset - 00f883abdb0c
[Not reviewed]
default
0 1 0
Marcin Kuzminski - 15 years ago 2010-09-05 13:55:47
marcin@python-works.com
fixed a bug when given wrong username at login
broken in last reimplemntation of forms
1 file changed with 1 insertions and 4 deletions:
0 comments (0 inline, 0 general)
pylons_app/model/forms.py
Show inline comments
 
@@ -74,53 +74,50 @@ def ValidUsername(edit, old_data):
 
                            
 
    return _ValidUsername   
 
    
 
class ValidPassword(formencode.validators.FancyValidator):
 
    
 
    def to_python(self, value, state):
 
        if value:
 
            return get_crypt_password(value)
 
        
 
class ValidAuth(formencode.validators.FancyValidator):
 
    messages = {
 
            'invalid_password':_('invalid password'),
 
            'invalid_login':_('invalid user name'),
 
            'disabled_account':_('Your acccount is disabled')
 
            
 
            }
 
    #error mapping
 
    e_dict = {'username':messages['invalid_login'],
 
              'password':messages['invalid_password']}
 
    e_dict_disable = {'username':messages['disabled_account']}
 
    
 
    def validate_python(self, value, state):
 
        password = value['password']
 
        username = value['username']
 
        try:
 
            user = UserModel().get_user_by_name(username)
 
        except (NoResultFound, MultipleResultsFound, OperationalError) as e:
 
            log.error(e)
 
            user = None
 
        if user is None:
 
            raise formencode.Invalid(self.message('invalid_password',
 
                                     state=State_obj), value, state,
 
                                     error_dict=self.e_dict)            
 
        if user:
 
            if user.active:
 
                if user.username == username and check_password(password, 
 
                                                                user.password):
 
                    return value
 
                else:
 
                    log.warning('user %s not authenticated', username)
 
                    raise formencode.Invalid(self.message('invalid_password',
 
                                             state=State_obj), value, state,
 
                                             error_dict=self.e_dict)
 
            else:
 
                log.warning('user %s is disabled', username)
 
                raise formencode.Invalid(self.message('disabled_account',
 
                                         state=State_obj),
 
                                         value, state,
 
                                         error_dict=self.e_dict_disable)
 
                   
 
class ValidRepoUser(formencode.validators.FancyValidator):
 
            
 
    def to_python(self, value, state):
 
        try:
0 comments (0 inline, 0 general)