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