From 9c73b32de11b7b098b2da55ddb031394ff307b7d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 30 Jan 2010 23:39:44 +0200 Subject: [PATCH] Added the activation template, and completed the registration/activation process. --- scribeengine/controllers/admin.py | 33 +++++++++++++++++++--- scribeengine/lib/utils.py | 4 +-- scribeengine/templates/email/activate.mako | 21 ++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 scribeengine/templates/email/activate.mako diff --git a/scribeengine/controllers/admin.py b/scribeengine/controllers/admin.py index c40b922..ff599d7 100644 --- a/scribeengine/controllers/admin.py +++ b/scribeengine/controllers/admin.py @@ -23,6 +23,7 @@ import logging import string import random +from datetime import datetime from scribeengine.lib.base import * from scribeengine.lib.validation.client import JSString, JSEmail @@ -47,7 +48,7 @@ class AdminController(BaseController): 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.') + u'confirm-password': JSString(required=True, equalTo=u'#password', message=u'Your passwords don\'t match.') } def register_schema(self): @@ -67,6 +68,26 @@ class AdminController(BaseController): ) 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 activate(self, id=None): @@ -79,8 +100,8 @@ class AdminController(BaseController): h.flash.set_message(u'Your username was missing or incorrect. ' u'Please check your activation e-mail.', u'error') h.redirect_to(h.url_for(action=u'register')) - user = Session.get(User)\ - .filter_by(email=id)\ + user = Session.query(User)\ + .filter_by(id=id)\ .filter_by(activation_key=activation_code)\ .first() if not user: @@ -88,9 +109,13 @@ class AdminController(BaseController): u'incorrect. Please check your activation e-mail.', u'error') h.redirect_to(h.url_for(action=u'register')) user.activation_key = None + user.modified = datetime.now() Session.add(user) Session.commit() - return render(u'/admin/activate.mako') + h.flash.set_message(u'Your account has been activated! Please log in ' + u'with your e-mail address and the password you typed in during ' + u'registration.', u'success') + h.redirect_to(h.url_for(action=u'login')) def login(self): c.page_title = u'Login' diff --git a/scribeengine/lib/utils.py b/scribeengine/lib/utils.py index a2c0d9e..434b252 100644 --- a/scribeengine/lib/utils.py +++ b/scribeengine/lib/utils.py @@ -27,10 +27,10 @@ import string from random import choice from datetime import datetime -from pylons import config +from pylons import config, c from turbomail import Message -from scribeengine.lib.base import render, c +from scribeengine.lib.base import render def send_mail(template, mail_to, mail_from, subject, variables={}, attachments=[]): """ diff --git a/scribeengine/templates/email/activate.mako b/scribeengine/templates/email/activate.mako new file mode 100644 index 0000000..30e7d57 --- /dev/null +++ b/scribeengine/templates/email/activate.mako @@ -0,0 +1,21 @@ +Dear ${c.user.nick}, + +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)} + +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 +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)} + +Once you have completed the registration process you will be able to comment on +the posts on the site. + +Kind regards, + +${c.blog_title} Team