Added activate method.

This commit is contained in:
Raoul Snyman 2010-01-25 23:32:48 +02:00
parent 0797f5799c
commit 9909eeab36

View File

@ -69,6 +69,29 @@ class AdminController(BaseController):
Session.commit() Session.commit()
h.redirect_to('/') h.redirect_to('/')
def activate(self, id=None):
activation_code = request.GET.get('code')
if not activation_code:
h.flash.set_message(u'Your activation code was missing or '
u'incorrect. Please check your activation e-mail.', u'error')
h.redirect_to(h.url_for(action=u'register'))
if not id:
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)\
.filter_by(activation_key=activation_code)\
.first()
if not user:
h.flash.set_message(u'Your username or activation code is '
u'incorrect. Please check your activation e-mail.', u'error')
h.redirect_to(h.url_for(action=u'register'))
user.activation_key = None
Session.add(user)
Session.commit()
return render(u'/admin/activate.mako')
def login(self): def login(self):
c.page_title = u'Login' c.page_title = u'Login'
return render(u'/admin/login.mako') return render(u'/admin/login.mako')