##// END OF EJS Templates
Added validation into user email map
marcink -
r2479:92255976 beta
parent child Browse files
Show More
@@ -125,12 +125,15 b' class UsersController(BaseController):'
125 h.flash(_('User updated successfully'), category='success')
125 h.flash(_('User updated successfully'), category='success')
126 Session.commit()
126 Session.commit()
127 except formencode.Invalid, errors:
127 except formencode.Invalid, errors:
128 c.user_email_map = UserEmailMap.query()\
129 .filter(UserEmailMap.user == c.user).all()
130 defaults = errors.value
128 e = errors.error_dict or {}
131 e = errors.error_dict or {}
129 perm = Permission.get_by_key('hg.create.repository')
132 perm = Permission.get_by_key('hg.create.repository')
130 e.update({'create_repo_perm': user_model.has_perm(id, perm)})
133 defaults.update({'create_repo_perm': user_model.has_perm(id, perm)})
131 return htmlfill.render(
134 return htmlfill.render(
132 render('admin/users/user_edit.html'),
135 render('admin/users/user_edit.html'),
133 defaults=errors.value,
136 defaults=defaults,
134 errors=e,
137 errors=e,
135 prefix_error=False,
138 prefix_error=False,
136 encoding="UTF-8")
139 encoding="UTF-8")
@@ -231,6 +234,9 b' class UsersController(BaseController):'
231 user_model.add_extra_email(id, email)
234 user_model.add_extra_email(id, email)
232 Session.commit()
235 Session.commit()
233 h.flash(_("Added email %s to user" % email), category='success')
236 h.flash(_("Added email %s to user" % email), category='success')
237 except formencode.Invalid, error:
238 msg = error.error_dict['email']
239 h.flash(msg, category='error')
234 except Exception:
240 except Exception:
235 log.error(traceback.format_exc())
241 log.error(traceback.format_exc())
236 h.flash(_('An error occurred during email saving'),
242 h.flash(_('An error occurred during email saving'),
@@ -38,11 +38,6 b' from pylons.i18n.translation import _'
38 from rhodecode import __platform__, PLATFORM_WIN, PLATFORM_OTHERS
38 from rhodecode import __platform__, PLATFORM_WIN, PLATFORM_OTHERS
39 from rhodecode.model.meta import Session
39 from rhodecode.model.meta import Session
40
40
41 if __platform__ in PLATFORM_WIN:
42 from hashlib import sha256
43 if __platform__ in PLATFORM_OTHERS:
44 import bcrypt
45
46 from rhodecode.lib.utils2 import str2bool, safe_unicode
41 from rhodecode.lib.utils2 import str2bool, safe_unicode
47 from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError
42 from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError
48 from rhodecode.lib.utils import get_repo_slug, get_repos_group_slug
43 from rhodecode.lib.utils import get_repo_slug, get_repos_group_slug
@@ -98,8 +93,10 b' class RhodeCodeCrypto(object):'
98 :param password: password to hash
93 :param password: password to hash
99 """
94 """
100 if __platform__ in PLATFORM_WIN:
95 if __platform__ in PLATFORM_WIN:
96 from hashlib import sha256
101 return sha256(str_).hexdigest()
97 return sha256(str_).hexdigest()
102 elif __platform__ in PLATFORM_OTHERS:
98 elif __platform__ in PLATFORM_OTHERS:
99 import bcrypt
103 return bcrypt.hashpw(str_, bcrypt.gensalt(10))
100 return bcrypt.hashpw(str_, bcrypt.gensalt(10))
104 else:
101 else:
105 raise Exception('Unknown or unsupported platform %s' \
102 raise Exception('Unknown or unsupported platform %s' \
@@ -116,8 +113,10 b' class RhodeCodeCrypto(object):'
116 """
113 """
117
114
118 if __platform__ in PLATFORM_WIN:
115 if __platform__ in PLATFORM_WIN:
116 from hashlib import sha256
119 return sha256(password).hexdigest() == hashed
117 return sha256(password).hexdigest() == hashed
120 elif __platform__ in PLATFORM_OTHERS:
118 elif __platform__ in PLATFORM_OTHERS:
119 import bcrypt
121 return bcrypt.hashpw(password, hashed) == hashed
120 return bcrypt.hashpw(password, hashed) == hashed
122 else:
121 else:
123 raise Exception('Unknown or unsupported platform %s' \
122 raise Exception('Unknown or unsupported platform %s' \
@@ -299,3 +299,10 b' def LdapSettingsForm(tls_reqcert_choices'
299 ldap_attr_email = v.UnicodeString(strip=True,)
299 ldap_attr_email = v.UnicodeString(strip=True,)
300
300
301 return _LdapSettingsForm
301 return _LdapSettingsForm
302
303
304 def UserExtraEmailForm():
305 class _UserExtraEmailForm(formencode.Schema):
306 email = All(v.UniqSystemEmail(), v.Email)
307
308 return _UserExtraEmailForm No newline at end of file
@@ -29,9 +29,11 b' import traceback'
29 from pylons import url
29 from pylons import url
30 from pylons.i18n.translation import _
30 from pylons.i18n.translation import _
31
31
32 from sqlalchemy.exc import DatabaseError
33 from sqlalchemy.orm import joinedload
34
32 from rhodecode.lib.utils2 import safe_unicode, generate_api_key
35 from rhodecode.lib.utils2 import safe_unicode, generate_api_key
33 from rhodecode.lib.caching_query import FromCache
36 from rhodecode.lib.caching_query import FromCache
34
35 from rhodecode.model import BaseModel
37 from rhodecode.model import BaseModel
36 from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \
38 from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \
37 UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \
39 UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \
@@ -40,9 +42,6 b' from rhodecode.model.db import User, Use'
40 from rhodecode.lib.exceptions import DefaultUserException, \
42 from rhodecode.lib.exceptions import DefaultUserException, \
41 UserOwnsReposException
43 UserOwnsReposException
42
44
43 from sqlalchemy.exc import DatabaseError
44
45 from sqlalchemy.orm import joinedload
46
45
47 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
48
47
@@ -593,10 +592,14 b' class UserModel(BaseModel):'
593 :param user:
592 :param user:
594 :param email:
593 :param email:
595 """
594 """
595 from rhodecode.model import forms
596 form = forms.UserExtraEmailForm()()
597 data = form.to_python(dict(email=email))
596 user = self._get_user(user)
598 user = self._get_user(user)
599
597 obj = UserEmailMap()
600 obj = UserEmailMap()
598 obj.user = user
601 obj.user = user
599 obj.email = email
602 obj.email = data['email']
600 self.sa.add(obj)
603 self.sa.add(obj)
601 return obj
604 return obj
602
605
@@ -14,7 +14,6 b' from formencode.validators import ('
14
14
15 from rhodecode.lib.utils import repo_name_slug
15 from rhodecode.lib.utils import repo_name_slug
16 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User
16 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User
17 from rhodecode.lib.auth import authenticate
18 from rhodecode.lib.exceptions import LdapImportError
17 from rhodecode.lib.exceptions import LdapImportError
19 from rhodecode.config.routing import ADMIN_PREFIX
18 from rhodecode.config.routing import ADMIN_PREFIX
20 # silence warnings and pylint
19 # silence warnings and pylint
@@ -241,6 +240,8 b' def ValidAuth():'
241 }
240 }
242
241
243 def validate_python(self, value, state):
242 def validate_python(self, value, state):
243 from rhodecode.lib.auth import authenticate
244
244 password = value['password']
245 password = value['password']
245 username = value['username']
246 username = value['username']
246
247
General Comments 0
You need to be logged in to leave comments. Login now