Browse Source

registration verification mail contains link expiry datetime

master
Holger Frey 7 years ago
parent
commit
e974070585
  1. 3
      ordr2/templates/emails/registration.jinja2
  2. 4
      ordr2/views/account.py
  3. 7
      tests/events.py

3
ordr2/templates/emails/registration.jinja2

@ -9,8 +9,9 @@
<h1>Hi there!</h1> <h1>Hi there!</h1>
<p> <p>
Please verify your email address for the account "{{ user.user_name }}" by following this link Please verify your email address for the account "{{ user.user_name }}" by following this link
<a href="{{ request.resource_url(context, data.hash) }}">{{ request.resource_url(context, data.hash) }}</a> <a href="{{ request.resource_url(context, data.token.hash) }}">{{ request.resource_url(context, data.token.hash) }}</a>
</p> </p>
<p> The link will expire on {{ data.token.expires.strftime('%d.%m.%y at %H:%M') }}.
<p class="signature"> <p class="signature">
Regards, Regards,
<br/> <br/>

4
ordr2/views/account.py

@ -95,8 +95,8 @@ def registration_form_processing(context, request):
request.dbsession.add(account) request.dbsession.add(account)
# create a verify-new-account token and send email # create a verify-new-account token and send email
hash = account.issue_token(request, TokenSubject.USER_REGISTRATION) token = account.issue_token(request, TokenSubject.USER_REGISTRATION)
notification = CompleteRegistration(request, account, {'hash': hash}) notification = CompleteRegistration(request, account, {'token': token})
request.registry.notify(notification) request.registry.notify(notification)
# issue a warning on a short password # issue a warning on a short password

7
tests/events.py

@ -2,6 +2,7 @@
import pytest import pytest
from datetime import datetime
from pyramid.testing import DummyRequest from pyramid.testing import DummyRequest
from pyramid_mailer import get_mailer from pyramid_mailer import get_mailer
@ -21,13 +22,15 @@ def test_user_notification_init():
def test_notify_user(app_config): def test_notify_user(app_config):
from ordr2.events import CompleteRegistration, notify_user from ordr2.events import CompleteRegistration, notify_user
from ordr2.models.account import Token
request = DummyRequest() request = DummyRequest()
user = get_user('user') user = get_user('user')
notification = CompleteRegistration(request, user, {'hash': 'something'}) token = Token(expires=datetime.utcnow(), hash='some_hash')
notification = CompleteRegistration(request, user, {'token': token})
notify_user(notification) notify_user(notification)
mailer = get_mailer(request.registry) mailer = get_mailer(request.registry)
last_mail = mailer.outbox[-1] last_mail = mailer.outbox[-1]
assert 'Please verify your email address ' in last_mail.html assert 'Please verify your email address ' in last_mail.html
assert 'http://example.com//something' in last_mail.html assert 'http://example.com//some_hash' in last_mail.html