From e26f3aa3c4e6e034d0d0cb7e945d55e832d5951b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 11 Feb 2010 22:09:31 +0200 Subject: [PATCH] Added "reset password" e-mail template. --- scribeengine/controllers/account.py | 53 ++++++++++++++++++++++ scribeengine/templates/email/activate.mako | 6 +-- scribeengine/templates/email/reset.mako | 11 +++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 scribeengine/templates/email/reset.mako diff --git a/scribeengine/controllers/account.py b/scribeengine/controllers/account.py index 97a14e2..bfd47df 100644 --- a/scribeengine/controllers/account.py +++ b/scribeengine/controllers/account.py @@ -117,6 +117,59 @@ class AccountController(BaseController): u'registration.', u'success') h.redirect_to(h.url_for(controller=u'account', action=u'login')) + def reset(self): + c.page_title = u'Reset Password' + return render(u'/account/reset.mako') + + @jsvalidate(u'reset-form') + def reset_jsschema(self): + return { + u'email': JSEmail(required=True, message=u'You haven\'t typed in an e-mail address.'), + u'password': JSString(required=True, message=u'You haven\'t typed in a password.'), + u'confirm-password': JSString(required=True, equalTo=u'#password', message=u'Your passwords don\'t match.') + } + + def reset_schema(self): + return { + 'email': Email(not_empty=True, messages={'empty': u'You haven\'t typed in an e-mail address.'}), + 'password': UnicodeString(not_empty=True, messages={'empty': u'You haven\'t typed in a password.'}), + 'confirm': [FieldsMatch('password', 'confirm-passsword', messages={'invalid': u'Your passwords don\'t match.'})] + } + + def reset_POST(self): + email = c.form_values[u'email'] + user = Session.query(User).filter_by(email=email).first() + if not user: + h.flash.set_message(u'Your e-mail address is not in the system.', u'error') + else: + activation_code = u''.join(random.sample(string.letters + string.digits, 40)) + user.password = utils.hash_password(activation_code), + user.activation_key = activation_code + user.modified = datetime.now() + Session.add(user) + Session.commit() + blog_mail = Session.query(Variable).get(u'blog mail') + blog_title = Session.query(Variable).get(u'blog title') + blog_host = Session.query(Variable).get(u'blog host') + if not blog_host: + url = u'%s://%s' % (request.environ[u'wsgi.url_scheme'], + request.environ[u'HTTP_HOST']) + blog_host = Variable(key=u'blog host', value=url) + Session.add(blog_host) + Session.commit() + utils.send_mail(u'/email/activate.mako', u'%s <%s>' % (user.nick, user.email), + u'%s <%s>' % (blog_mail.value, blog_title.value), + u'[%s] Activate your account!' % blog_title.value, + { + 'user': user, + 'blog_title': blog_title.value, + 'blog_host': blog_host.value + }) + h.flash.set_message(u'An e-mail has been sent to your e-mail address. ' + u'Please activate your account by clicking on the link in your ' + u'e-mail.', u'success') + h.redirect_to('/') + def login(self): c.page_title = u'Login' return render(u'/account/login.mako') diff --git a/scribeengine/templates/email/activate.mako b/scribeengine/templates/email/activate.mako index 30e7d57..3b96404 100644 --- a/scribeengine/templates/email/activate.mako +++ b/scribeengine/templates/email/activate.mako @@ -4,14 +4,14 @@ You have just registered on ${c.blog_title}, but before you continue, you will need to activate your account. You can do this by simply clicking on the link below, or copying and pasting it into your browser. -${c.blog_host}${h.url_for(controller=u'admin', action=u'activate', id=c.user.id, code=c.user.activation_key)} +${c.blog_host}${h.url_for(controller=u'account', action=u'activate', id=c.user.id, code=c.user.activation_key)} If this is not you, simply leave this e-mail, and the account will expire after 72 hours. If you left this e-mail for too long and want to continue with the -registration process, click on the link below, type in your e-mail addres, and +registration process, click on the link below, type in your e-mail address, and another e-mail will be sent to you to activate your account. -${c.blog_host}${h.url_for(controller=u'admin', action=u'reset', id=c.user.id)} +${c.blog_host}${h.url_for(controller=u'account', action=u'reset', id=c.user.id)} Once you have completed the registration process you will be able to comment on the posts on the site. diff --git a/scribeengine/templates/email/reset.mako b/scribeengine/templates/email/reset.mako new file mode 100644 index 0000000..b3f1c12 --- /dev/null +++ b/scribeengine/templates/email/reset.mako @@ -0,0 +1,11 @@ +Dear ${c.user.nick}, + +You have just reset your password on ${c.blog_title}, but before you continue, +you will need to activate your account. You can do this by simply clicking on +the link below, or copying and pasting it into your browser. + +${c.blog_host}${h.url_for(controller=u'account', action=u'activate', id=c.user.id, code=c.user.activation_key)} + +Kind regards, + +${c.blog_title} Team