diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2013-02-25 21:27:52 +0100 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2013-02-25 21:27:52 +0100 |
commit | 920bb05d6b6351bdaa8390cd1b08a4243f20d1b7 (patch) | |
tree | 98af36837679f650f09bbbd7544ce333b69f2b25 | |
parent | c5160f484d6c51761e4e1b14824a7279597941a5 (diff) |
moved out password reset tasks from celery, it doesn't make any sense to keep them there, additionally they are broken
in when executing _(), and url() calls. This fixes issue #572
--HG--
extra : source : 5c310b7b01cec6472e9c144123ce13ebbec83148
-rw-r--r-- | rhodecode/lib/celerylib/tasks.py | 66 | ||||
-rw-r--r-- | rhodecode/model/user.py | 55 | ||||
-rw-r--r-- | rhodecode/templates/email_templates/password_reset.html | 15 |
3 files changed, 60 insertions, 76 deletions
diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py index 0a72f0f0..1e7d678e 100644 --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -247,72 +247,6 @@ def get_commits_stats(repo_name, ts_min_y, ts_max_y): log.info('LockHeld') return 'Task with key %s already running' % lockkey -@task(ignore_result=True) -@dbsession -def send_password_link(user_email): - from rhodecode.model.notification import EmailNotificationModel - - log = get_logger(send_password_link) - DBS = get_session() - - try: - user = User.get_by_email(user_email) - if user: - log.debug('password reset user found %s' % user) - link = url('reset_password_confirmation', key=user.api_key, - qualified=True) - reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET - body = EmailNotificationModel().get_email_tmpl(reg_type, - **{'user':user.short_contact, - 'reset_url':link}) - log.debug('sending email') - run_task(send_email, user_email, - _("password reset link"), body) - log.info('send new password mail to %s' % user_email) - else: - log.debug("password reset email %s not found" % user_email) - except: - log.error(traceback.format_exc()) - return False - - return True - -@task(ignore_result=True) -@dbsession -def reset_user_password(user_email): - from rhodecode.lib import auth - - log = get_logger(reset_user_password) - DBS = get_session() - - try: - try: - user = User.get_by_email(user_email) - new_passwd = auth.PasswordGenerator().gen_password(8, - auth.PasswordGenerator.ALPHABETS_BIG_SMALL) - if user: - user.password = auth.get_crypt_password(new_passwd) - user.api_key = auth.generate_api_key(user.username) - DBS.add(user) - DBS.commit() - log.info('change password for %s' % user_email) - if new_passwd is None: - raise Exception('unable to generate new password') - except: - log.error(traceback.format_exc()) - DBS.rollback() - - run_task(send_email, user_email, - 'Your new password', - 'Your new RhodeCode password:%s' % (new_passwd)) - log.info('send new password mail to %s' % user_email) - - except: - log.error('Failed to update user password') - log.error(traceback.format_exc()) - - return True - @task(ignore_result=True) @dbsession diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py index 453c6472..956d4a29 100644 --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -42,6 +42,7 @@ from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \ UserEmailMap, UserIpMap from rhodecode.lib.exceptions import DefaultUserException, \ UserOwnsReposException +from rhodecode.model.meta import Session log = logging.getLogger(__name__) @@ -316,11 +317,61 @@ class UserModel(BaseModel): def reset_password_link(self, data): from rhodecode.lib.celerylib import tasks, run_task - run_task(tasks.send_password_link, data['email']) + from rhodecode.model.notification import EmailNotificationModel + user_email = data['email'] + try: + user = User.get_by_email(user_email) + if user: + log.debug('password reset user found %s' % user) + link = url('reset_password_confirmation', key=user.api_key, + qualified=True) + reg_type = EmailNotificationModel.TYPE_PASSWORD_RESET + body = EmailNotificationModel().get_email_tmpl(reg_type, + **{'user': user.short_contact, + 'reset_url': link}) + log.debug('sending email') + run_task(tasks.send_email, user_email, + _("password reset link"), body, body) + log.info('send new password mail to %s' % user_email) + else: + log.debug("password reset email %s not found" % user_email) + except: + log.error(traceback.format_exc()) + return False + + return True def reset_password(self, data): from rhodecode.lib.celerylib import tasks, run_task - run_task(tasks.reset_user_password, data['email']) + from rhodecode.lib import auth + user_email = data['email'] + try: + try: + user = User.get_by_email(user_email) + new_passwd = auth.PasswordGenerator().gen_password(8, + auth.PasswordGenerator.ALPHABETS_BIG_SMALL) + if user: + user.password = auth.get_crypt_password(new_passwd) + user.api_key = auth.generate_api_key(user.username) + Session().add(user) + Session().commit() + log.info('change password for %s' % user_email) + if new_passwd is None: + raise Exception('unable to generate new password') + except: + log.error(traceback.format_exc()) + Session().rollback() + + run_task(tasks.send_email, user_email, + _('Your new password'), + _('Your new RhodeCode password:%s') % (new_passwd)) + log.info('send new password mail to %s' % user_email) + + except: + log.error('Failed to update user password') + log.error(traceback.format_exc()) + + return True def fill_data(self, auth_user, user_id=None, api_key=None): """ diff --git a/rhodecode/templates/email_templates/password_reset.html b/rhodecode/templates/email_templates/password_reset.html index 3978f3ec..936f9941 100644 --- a/rhodecode/templates/email_templates/password_reset.html +++ b/rhodecode/templates/email_templates/password_reset.html @@ -1,12 +1,11 @@ ## -*- coding: utf-8 -*- <%inherit file="main.html"/> -${_('Hello')} ${user} - -${_('We received a request to create a new password for your account.')} - -${_('You can generate it by clicking following URL')}: - +<h4>${_('Hello %s') % user}</h4> +<div>${_('We received a request to create a new password for your account.')}</div> +<div>${_('You can generate it by clicking following URL')}:</div> +<pre> ${reset_url} - -${_("If you didn't request new password please ignore this email.")} +</pre> +<br/> +${_("If you did not request new password please ignore this email.")} |