Mercurial > kallithea
comparison rhodecode/model/forms.py @ 699:52da7cba88a6 beta
Code refactor for auth func, preparing for ldap support
css updates.
turned off graph,and branches for git changelog
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 16 Nov 2010 08:52:31 +0100 |
parents | dd532af216d9 |
children | 9e9f1b919c0c |
comparison
equal
deleted
inserted
replaced
698:4cd0709b6d4b | 699:52da7cba88a6 |
---|---|
22 from formencode import All | 22 from formencode import All |
23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \ | 23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \ |
24 Email, Bool, StringBoolean | 24 Email, Bool, StringBoolean |
25 from pylons import session | 25 from pylons import session |
26 from pylons.i18n.translation import _ | 26 from pylons.i18n.translation import _ |
27 from rhodecode.lib.auth import check_password, get_crypt_password | 27 from rhodecode.lib.auth import authfunc, get_crypt_password |
28 from rhodecode.model import meta | 28 from rhodecode.model import meta |
29 from rhodecode.model.user import UserModel | 29 from rhodecode.model.user import UserModel |
30 from rhodecode.model.repo import RepoModel | 30 from rhodecode.model.repo import RepoModel |
31 from rhodecode.model.db import User | 31 from rhodecode.model.db import User |
32 from webhelpers.pylonslib.secure_form import authentication_token | 32 from webhelpers.pylonslib.secure_form import authentication_token |
92 | 92 |
93 def validate_python(self, value, state): | 93 def validate_python(self, value, state): |
94 password = value['password'] | 94 password = value['password'] |
95 username = value['username'] | 95 username = value['username'] |
96 user = UserModel().get_by_username(username) | 96 user = UserModel().get_by_username(username) |
97 if user is None: | 97 |
98 raise formencode.Invalid(self.message('invalid_password', | 98 if authfunc(None, username, password): |
99 state=State_obj), value, state, | 99 return value |
100 error_dict=self.e_dict) | 100 else: |
101 if user: | 101 if user and user.active is False: |
102 if user.active: | |
103 if user.username == username and check_password(password, | |
104 user.password): | |
105 return value | |
106 else: | |
107 log.warning('user %s not authenticated', username) | |
108 raise formencode.Invalid(self.message('invalid_password', | |
109 state=State_obj), value, state, | |
110 error_dict=self.e_dict) | |
111 else: | |
112 log.warning('user %s is disabled', username) | 102 log.warning('user %s is disabled', username) |
113 raise formencode.Invalid(self.message('disabled_account', | 103 raise formencode.Invalid(self.message('disabled_account', |
114 state=State_obj), | 104 state=State_obj), |
115 value, state, | 105 value, state, |
116 error_dict=self.e_dict_disable) | 106 error_dict=self.e_dict_disable) |
107 else: | |
108 log.warning('user %s not authenticated', username) | |
109 raise formencode.Invalid(self.message('invalid_password', | |
110 state=State_obj), value, state, | |
111 error_dict=self.e_dict) | |
117 | 112 |
118 class ValidRepoUser(formencode.validators.FancyValidator): | 113 class ValidRepoUser(formencode.validators.FancyValidator): |
119 | 114 |
120 def to_python(self, value, state): | 115 def to_python(self, value, state): |
121 sa = meta.Session() | 116 sa = meta.Session() |