Show More
@@ -251,72 +251,6 b' def get_commits_stats(repo_name, ts_min_' | |||||
251 | log.info('LockHeld') |
|
251 | log.info('LockHeld') | |
252 | return 'Task with key %s already running' % lockkey |
|
252 | return 'Task with key %s already running' % lockkey | |
253 |
|
253 | |||
254 | @task(ignore_result=True) |
|
|||
255 | @dbsession |
|
|||
256 | def send_password_link(user_email): |
|
|||
257 | from rhodecode.model.notification import EmailNotificationModel |
|
|||
258 |
|
||||
259 | log = get_logger(send_password_link) |
|
|||
260 | DBS = get_session() |
|
|||
261 |
|
||||
262 | try: |
|
|||
263 | user = User.get_by_email(user_email) |
|
|||
264 | if user: |
|
|||
265 | log.debug('password reset user found %s' % user) |
|
|||
266 | link = url('reset_password_confirmation', key=user.api_key, |
|
|||
267 | qualified=True) |
|
|||
268 | reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET |
|
|||
269 | body = EmailNotificationModel().get_email_tmpl(reg_type, |
|
|||
270 | **{'user':user.short_contact, |
|
|||
271 | 'reset_url':link}) |
|
|||
272 | log.debug('sending email') |
|
|||
273 | run_task(send_email, user_email, |
|
|||
274 | _("password reset link"), body) |
|
|||
275 | log.info('send new password mail to %s' % user_email) |
|
|||
276 | else: |
|
|||
277 | log.debug("password reset email %s not found" % user_email) |
|
|||
278 | except: |
|
|||
279 | log.error(traceback.format_exc()) |
|
|||
280 | return False |
|
|||
281 |
|
||||
282 | return True |
|
|||
283 |
|
||||
284 | @task(ignore_result=True) |
|
|||
285 | @dbsession |
|
|||
286 | def reset_user_password(user_email): |
|
|||
287 | from rhodecode.lib import auth |
|
|||
288 |
|
||||
289 | log = get_logger(reset_user_password) |
|
|||
290 | DBS = get_session() |
|
|||
291 |
|
||||
292 | try: |
|
|||
293 | try: |
|
|||
294 | user = User.get_by_email(user_email) |
|
|||
295 | new_passwd = auth.PasswordGenerator().gen_password(8, |
|
|||
296 | auth.PasswordGenerator.ALPHABETS_BIG_SMALL) |
|
|||
297 | if user: |
|
|||
298 | user.password = auth.get_crypt_password(new_passwd) |
|
|||
299 | user.api_key = auth.generate_api_key(user.username) |
|
|||
300 | DBS.add(user) |
|
|||
301 | DBS.commit() |
|
|||
302 | log.info('change password for %s' % user_email) |
|
|||
303 | if new_passwd is None: |
|
|||
304 | raise Exception('unable to generate new password') |
|
|||
305 | except: |
|
|||
306 | log.error(traceback.format_exc()) |
|
|||
307 | DBS.rollback() |
|
|||
308 |
|
||||
309 | run_task(send_email, user_email, |
|
|||
310 | 'Your new password', |
|
|||
311 | 'Your new RhodeCode password:%s' % (new_passwd)) |
|
|||
312 | log.info('send new password mail to %s' % user_email) |
|
|||
313 |
|
||||
314 | except: |
|
|||
315 | log.error('Failed to update user password') |
|
|||
316 | log.error(traceback.format_exc()) |
|
|||
317 |
|
||||
318 | return True |
|
|||
319 |
|
||||
320 |
|
254 | |||
321 | @task(ignore_result=True) |
|
255 | @task(ignore_result=True) | |
322 | @dbsession |
|
256 | @dbsession |
@@ -42,6 +42,7 b' from rhodecode.model.db import User, Use' | |||||
42 | UserEmailMap, UserIpMap |
|
42 | UserEmailMap, UserIpMap | |
43 | from rhodecode.lib.exceptions import DefaultUserException, \ |
|
43 | from rhodecode.lib.exceptions import DefaultUserException, \ | |
44 | UserOwnsReposException |
|
44 | UserOwnsReposException | |
|
45 | from rhodecode.model.meta import Session | |||
45 |
|
46 | |||
46 |
|
47 | |||
47 | log = logging.getLogger(__name__) |
|
48 | log = logging.getLogger(__name__) | |
@@ -316,11 +317,61 b' class UserModel(BaseModel):' | |||||
316 |
|
317 | |||
317 | def reset_password_link(self, data): |
|
318 | def reset_password_link(self, data): | |
318 | from rhodecode.lib.celerylib import tasks, run_task |
|
319 | from rhodecode.lib.celerylib import tasks, run_task | |
319 | run_task(tasks.send_password_link, data['email']) |
|
320 | from rhodecode.model.notification import EmailNotificationModel | |
|
321 | user_email = data['email'] | |||
|
322 | try: | |||
|
323 | user = User.get_by_email(user_email) | |||
|
324 | if user: | |||
|
325 | log.debug('password reset user found %s' % user) | |||
|
326 | link = url('reset_password_confirmation', key=user.api_key, | |||
|
327 | qualified=True) | |||
|
328 | reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET | |||
|
329 | body = EmailNotificationModel().get_email_tmpl(reg_type, | |||
|
330 | **{'user': user.short_contact, | |||
|
331 | 'reset_url': link}) | |||
|
332 | log.debug('sending email') | |||
|
333 | run_task(tasks.send_email, user_email, | |||
|
334 | _("password reset link"), body, body) | |||
|
335 | log.info('send new password mail to %s' % user_email) | |||
|
336 | else: | |||
|
337 | log.debug("password reset email %s not found" % user_email) | |||
|
338 | except: | |||
|
339 | log.error(traceback.format_exc()) | |||
|
340 | return False | |||
|
341 | ||||
|
342 | return True | |||
320 |
|
343 | |||
321 | def reset_password(self, data): |
|
344 | def reset_password(self, data): | |
322 | from rhodecode.lib.celerylib import tasks, run_task |
|
345 | from rhodecode.lib.celerylib import tasks, run_task | |
323 | run_task(tasks.reset_user_password, data['email']) |
|
346 | from rhodecode.lib import auth | |
|
347 | user_email = data['email'] | |||
|
348 | try: | |||
|
349 | try: | |||
|
350 | user = User.get_by_email(user_email) | |||
|
351 | new_passwd = auth.PasswordGenerator().gen_password(8, | |||
|
352 | auth.PasswordGenerator.ALPHABETS_BIG_SMALL) | |||
|
353 | if user: | |||
|
354 | user.password = auth.get_crypt_password(new_passwd) | |||
|
355 | user.api_key = auth.generate_api_key(user.username) | |||
|
356 | Session().add(user) | |||
|
357 | Session().commit() | |||
|
358 | log.info('change password for %s' % user_email) | |||
|
359 | if new_passwd is None: | |||
|
360 | raise Exception('unable to generate new password') | |||
|
361 | except: | |||
|
362 | log.error(traceback.format_exc()) | |||
|
363 | Session().rollback() | |||
|
364 | ||||
|
365 | run_task(tasks.send_email, user_email, | |||
|
366 | _('Your new password'), | |||
|
367 | _('Your new RhodeCode password:%s') % (new_passwd)) | |||
|
368 | log.info('send new password mail to %s' % user_email) | |||
|
369 | ||||
|
370 | except: | |||
|
371 | log.error('Failed to update user password') | |||
|
372 | log.error(traceback.format_exc()) | |||
|
373 | ||||
|
374 | return True | |||
324 |
|
375 | |||
325 | def fill_data(self, auth_user, user_id=None, api_key=None): |
|
376 | def fill_data(self, auth_user, user_id=None, api_key=None): | |
326 | """ |
|
377 | """ |
@@ -1,12 +1,11 b'' | |||||
1 | ## -*- coding: utf-8 -*- |
|
1 | ## -*- coding: utf-8 -*- | |
2 | <%inherit file="main.html"/> |
|
2 | <%inherit file="main.html"/> | |
3 |
|
3 | |||
4 |
${_('Hello |
|
4 | <h4>${_('Hello %s') % user}</h4> | |
5 |
|
5 | <div>${_('We received a request to create a new password for your account.')}</div> | ||
6 | ${_('We received a request to create a new password for your account.')} |
|
6 | <div>${_('You can generate it by clicking following URL')}:</div> | |
7 |
|
7 | <pre> | ||
8 | ${_('You can generate it by clicking following URL')}: |
|
|||
9 |
|
||||
10 | ${reset_url} |
|
8 | ${reset_url} | |
11 |
|
9 | </pre> | ||
12 | ${_("If you didn't request new password please ignore this email.")} |
|
10 | <br/> | |
|
11 | ${_("If you did not request new password please ignore this email.")} |
General Comments 0
You need to be logged in to leave comments.
Login now