Added "reset password" e-mail template.

This commit is contained in:
Raoul Snyman 2010-02-11 22:09:31 +02:00
parent a1af325882
commit e26f3aa3c4
3 changed files with 67 additions and 3 deletions

View File

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

View File

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

View File

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