##// END OF EJS Templates
Removed redundant Exception catching
marcink -
r4075:92da990f default
parent child Browse files
Show More
@@ -86,13 +86,13 b' class UserModel(BaseModel):'
86 86
87 87 from rhodecode.lib.hooks import log_create_user, check_allowed_create_user
88 88 _fd = form_data
89 form_data = {
89 user_data = {
90 90 'username': _fd['username'], 'password': _fd['password'],
91 91 'email': _fd['email'], 'firstname': _fd['firstname'], 'lastname': _fd['lastname'],
92 92 'active': _fd['active'], 'admin': False
93 93 }
94 94 # raises UserCreationError if it's not allowed
95 check_allowed_create_user(form_data, cur_user)
95 check_allowed_create_user(user_data, cur_user)
96 96
97 97 from rhodecode.lib.auth import get_crypt_password
98 98 try:
@@ -135,13 +135,13 b' class UserModel(BaseModel):'
135 135
136 136 from rhodecode.lib.auth import get_crypt_password
137 137 from rhodecode.lib.hooks import log_create_user, check_allowed_create_user
138 form_data = {
138 user_data = {
139 139 'username': username, 'password': password,
140 140 'email': email, 'firstname': firstname, 'lastname': lastname,
141 141 'active': active, 'admin': admin
142 142 }
143 143 # raises UserCreationError if it's not allowed
144 check_allowed_create_user(form_data, cur_user)
144 check_allowed_create_user(user_data, cur_user)
145 145
146 146 log.debug('Checking for %s account in RhodeCode database' % username)
147 147 user = User.get_by_username(username, case_insensitive=True)
@@ -194,13 +194,13 b' class UserModel(BaseModel):'
194 194 email = attrs['email'] or generate_email(username)
195 195
196 196 from rhodecode.lib.hooks import log_create_user, check_allowed_create_user
197 form_data = {
197 user_data = {
198 198 'username': username, 'password': None,
199 199 'email': email, 'firstname': firstname, 'lastname': lastname,
200 200 'active': attrs.get('active', True), 'admin': False
201 201 }
202 202 # raises UserCreationError if it's not allowed
203 check_allowed_create_user(form_data, cur_user)
203 check_allowed_create_user(user_data, cur_user)
204 204
205 205 try:
206 206 new_user = User()
@@ -248,13 +248,13 b' class UserModel(BaseModel):'
248 248 email = attrs['email'] or generate_email(username)
249 249
250 250 from rhodecode.lib.hooks import log_create_user, check_allowed_create_user
251 form_data = {
251 user_data = {
252 252 'username': username, 'password': password,
253 253 'email': email, 'firstname': firstname, 'lastname': lastname,
254 254 'active': attrs.get('active', True), 'admin': False
255 255 }
256 256 # raises UserCreationError if it's not allowed
257 check_allowed_create_user(form_data, cur_user)
257 check_allowed_create_user(user_data, cur_user)
258 258
259 259 try:
260 260 new_user = User()
@@ -411,23 +411,21 b' class UserModel(BaseModel):'
411 411 from rhodecode.lib.celerylib import tasks, run_task
412 412 from rhodecode.lib import auth
413 413 user_email = data['email']
414 pre_db = True
414 415 try:
415 try:
416 user = User.get_by_email(user_email)
417 new_passwd = auth.PasswordGenerator().gen_password(8,
418 auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
419 if user:
420 user.password = auth.get_crypt_password(new_passwd)
421 user.api_key = auth.generate_api_key(user.username)
422 Session().add(user)
423 Session().commit()
424 log.info('change password for %s' % user_email)
425 if new_passwd is None:
426 raise Exception('unable to generate new password')
427 except Exception:
428 log.error(traceback.format_exc())
429 Session().rollback()
416 user = User.get_by_email(user_email)
417 new_passwd = auth.PasswordGenerator().gen_password(8,
418 auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
419 if user:
420 user.password = auth.get_crypt_password(new_passwd)
421 user.api_key = auth.generate_api_key(user.username)
422 Session().add(user)
423 Session().commit()
424 log.info('change password for %s' % user_email)
425 if new_passwd is None:
426 raise Exception('unable to generate new password')
430 427
428 pre_db = False
431 429 run_task(tasks.send_email, user_email,
432 430 _('Your new password'),
433 431 _('Your new RhodeCode password:%s') % (new_passwd,))
@@ -436,6 +434,10 b' class UserModel(BaseModel):'
436 434 except Exception:
437 435 log.error('Failed to update user password')
438 436 log.error(traceback.format_exc())
437 if pre_db:
438 # we rollback only if local db stuff fails. If it goes into
439 # run_task, we're pass rollback state this wouldn't work then
440 Session().rollback()
439 441
440 442 return True
441 443
General Comments 0
You need to be logged in to leave comments. Login now