Show More
@@ -86,13 +86,13 b' class UserModel(BaseModel):' | |||||
86 |
|
86 | |||
87 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user |
|
87 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user | |
88 | _fd = form_data |
|
88 | _fd = form_data | |
89 |
|
|
89 | user_data = { | |
90 | 'username': _fd['username'], 'password': _fd['password'], |
|
90 | 'username': _fd['username'], 'password': _fd['password'], | |
91 | 'email': _fd['email'], 'firstname': _fd['firstname'], 'lastname': _fd['lastname'], |
|
91 | 'email': _fd['email'], 'firstname': _fd['firstname'], 'lastname': _fd['lastname'], | |
92 | 'active': _fd['active'], 'admin': False |
|
92 | 'active': _fd['active'], 'admin': False | |
93 | } |
|
93 | } | |
94 | # raises UserCreationError if it's not allowed |
|
94 | # raises UserCreationError if it's not allowed | |
95 |
check_allowed_create_user( |
|
95 | check_allowed_create_user(user_data, cur_user) | |
96 |
|
96 | |||
97 | from rhodecode.lib.auth import get_crypt_password |
|
97 | from rhodecode.lib.auth import get_crypt_password | |
98 | try: |
|
98 | try: | |
@@ -135,13 +135,13 b' class UserModel(BaseModel):' | |||||
135 |
|
135 | |||
136 | from rhodecode.lib.auth import get_crypt_password |
|
136 | from rhodecode.lib.auth import get_crypt_password | |
137 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user |
|
137 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user | |
138 |
|
|
138 | user_data = { | |
139 | 'username': username, 'password': password, |
|
139 | 'username': username, 'password': password, | |
140 | 'email': email, 'firstname': firstname, 'lastname': lastname, |
|
140 | 'email': email, 'firstname': firstname, 'lastname': lastname, | |
141 | 'active': active, 'admin': admin |
|
141 | 'active': active, 'admin': admin | |
142 | } |
|
142 | } | |
143 | # raises UserCreationError if it's not allowed |
|
143 | # raises UserCreationError if it's not allowed | |
144 |
check_allowed_create_user( |
|
144 | check_allowed_create_user(user_data, cur_user) | |
145 |
|
145 | |||
146 | log.debug('Checking for %s account in RhodeCode database' % username) |
|
146 | log.debug('Checking for %s account in RhodeCode database' % username) | |
147 | user = User.get_by_username(username, case_insensitive=True) |
|
147 | user = User.get_by_username(username, case_insensitive=True) | |
@@ -194,13 +194,13 b' class UserModel(BaseModel):' | |||||
194 | email = attrs['email'] or generate_email(username) |
|
194 | email = attrs['email'] or generate_email(username) | |
195 |
|
195 | |||
196 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user |
|
196 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user | |
197 |
|
|
197 | user_data = { | |
198 | 'username': username, 'password': None, |
|
198 | 'username': username, 'password': None, | |
199 | 'email': email, 'firstname': firstname, 'lastname': lastname, |
|
199 | 'email': email, 'firstname': firstname, 'lastname': lastname, | |
200 | 'active': attrs.get('active', True), 'admin': False |
|
200 | 'active': attrs.get('active', True), 'admin': False | |
201 | } |
|
201 | } | |
202 | # raises UserCreationError if it's not allowed |
|
202 | # raises UserCreationError if it's not allowed | |
203 |
check_allowed_create_user( |
|
203 | check_allowed_create_user(user_data, cur_user) | |
204 |
|
204 | |||
205 | try: |
|
205 | try: | |
206 | new_user = User() |
|
206 | new_user = User() | |
@@ -248,13 +248,13 b' class UserModel(BaseModel):' | |||||
248 | email = attrs['email'] or generate_email(username) |
|
248 | email = attrs['email'] or generate_email(username) | |
249 |
|
249 | |||
250 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user |
|
250 | from rhodecode.lib.hooks import log_create_user, check_allowed_create_user | |
251 |
|
|
251 | user_data = { | |
252 | 'username': username, 'password': password, |
|
252 | 'username': username, 'password': password, | |
253 | 'email': email, 'firstname': firstname, 'lastname': lastname, |
|
253 | 'email': email, 'firstname': firstname, 'lastname': lastname, | |
254 | 'active': attrs.get('active', True), 'admin': False |
|
254 | 'active': attrs.get('active', True), 'admin': False | |
255 | } |
|
255 | } | |
256 | # raises UserCreationError if it's not allowed |
|
256 | # raises UserCreationError if it's not allowed | |
257 |
check_allowed_create_user( |
|
257 | check_allowed_create_user(user_data, cur_user) | |
258 |
|
258 | |||
259 | try: |
|
259 | try: | |
260 | new_user = User() |
|
260 | new_user = User() | |
@@ -411,7 +411,7 b' class UserModel(BaseModel):' | |||||
411 | from rhodecode.lib.celerylib import tasks, run_task |
|
411 | from rhodecode.lib.celerylib import tasks, run_task | |
412 | from rhodecode.lib import auth |
|
412 | from rhodecode.lib import auth | |
413 | user_email = data['email'] |
|
413 | user_email = data['email'] | |
414 | try: |
|
414 | pre_db = True | |
415 |
|
|
415 | try: | |
416 |
|
|
416 | user = User.get_by_email(user_email) | |
417 |
|
|
417 | new_passwd = auth.PasswordGenerator().gen_password(8, | |
@@ -424,10 +424,8 b' class UserModel(BaseModel):' | |||||
424 |
|
|
424 | log.info('change password for %s' % user_email) | |
425 |
|
|
425 | if new_passwd is None: | |
426 |
|
|
426 | raise Exception('unable to generate new password') | |
427 | except Exception: |
|
|||
428 | log.error(traceback.format_exc()) |
|
|||
429 | Session().rollback() |
|
|||
430 |
|
427 | |||
|
428 | pre_db = False | |||
431 | run_task(tasks.send_email, user_email, |
|
429 | run_task(tasks.send_email, user_email, | |
432 | _('Your new password'), |
|
430 | _('Your new password'), | |
433 | _('Your new RhodeCode password:%s') % (new_passwd,)) |
|
431 | _('Your new RhodeCode password:%s') % (new_passwd,)) | |
@@ -436,6 +434,10 b' class UserModel(BaseModel):' | |||||
436 | except Exception: |
|
434 | except Exception: | |
437 | log.error('Failed to update user password') |
|
435 | log.error('Failed to update user password') | |
438 | log.error(traceback.format_exc()) |
|
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 | return True |
|
442 | return True | |
441 |
|
443 |
General Comments 0
You need to be logged in to leave comments.
Login now