Added the activation template, and completed the registration/activation process.

This commit is contained in:
Raoul Snyman 2010-01-30 23:39:44 +02:00
parent 9909eeab36
commit 9c73b32de1
3 changed files with 52 additions and 6 deletions

View File

@ -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'

View File

@ -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=[]):
"""

View File

@ -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