forked from bread-and-pepper/django-userena
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's now possible for the users to ask for a new activation key if th…
…e old one is expired
- Loading branch information
Showing
7 changed files
with
218 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends 'userena/base_userena.html' %} | ||
{% load i18n %} | ||
{% load url from future %} | ||
|
||
|
||
{% block title %}{% trans "Account activation failed." %}{% endblock %} | ||
{% block content_title %}<h2>{% trans "Your account could not be activated..." %}</h2>{% endblock %} | ||
|
||
{% block content %} | ||
<p>{% trans "Your account could not be activated because activation link is expired." %}</p> | ||
<p><a href="{% url 'userena_activate_retry' activation_key %}">{% trans "Request a new activation link." %}</a></p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends 'userena/base_userena.html' %} | ||
{% load i18n %} | ||
{% load url from future %} | ||
|
||
|
||
{% block title %}{% trans "Account re-activation succeded." %}{% endblock %} | ||
{% block content_title %}<h2>{% trans "Account re-activation" %}</h2>{% endblock %} | ||
|
||
{% block content %} | ||
<p>{% blocktrans %}You requested a new activation of your account..{% endblocktrans %}</p> | ||
<p>{% blocktrans %}You have been sent an e-mail with an activation link to the supplied email.{% endblocktrans %}</p> | ||
<p>{% blocktrans %}We will store your signup information for {{ userena_activation_days }} days on our server. {% endblocktrans %}</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from datetime import datetime, timedelta | ||
from django.core.urlresolvers import reverse | ||
from django.core import mail | ||
from django.contrib.auth.forms import PasswordChangeForm | ||
from django.conf import settings | ||
from django.test.utils import override_settings | ||
|
||
from userena import forms | ||
from userena import settings as userena_settings | ||
|
@@ -33,6 +35,65 @@ def test_valid_activation(self): | |
user = User.objects.get(email='[email protected]') | ||
self.failUnless(user.is_active) | ||
|
||
def test_activation_expired_retry(self): | ||
""" A ``GET`` to the activation view when activation link is expired """ | ||
# First, register an account. | ||
userena_settings.USERENA_ACTIVATION_RETRY = True | ||
self.client.post(reverse('userena_signup'), | ||
data={'username': 'alice', | ||
'email': '[email protected]', | ||
'password1': 'swordfish', | ||
'password2': 'swordfish', | ||
'tos': 'on'}) | ||
user = User.objects.get(email='[email protected]') | ||
user.date_joined = datetime.today() - timedelta(days=30) | ||
user.save() | ||
response = self.client.get(reverse('userena_activate', | ||
kwargs={'activation_key': user.userena_signup.activation_key})) | ||
self.assertContains(response, "Request a new activation link") | ||
|
||
user = User.objects.get(email='[email protected]') | ||
self.failUnless(not user.is_active) | ||
userena_settings.USERENA_ACTIVATION_RETRY = False | ||
|
||
def test_retry_activation_ask(self): | ||
""" Ask for a new activation link """ | ||
# First, register an account. | ||
userena_settings.USERENA_ACTIVATION_RETRY = True | ||
self.client.post(reverse('userena_signup'), | ||
data={'username': 'alice', | ||
'email': '[email protected]', | ||
'password1': 'swordfish', | ||
'password2': 'swordfish', | ||
'tos': 'on'}) | ||
user = User.objects.get(email='[email protected]') | ||
user.date_joined = datetime.today() - timedelta(days=30) | ||
user.save() | ||
old_key = user.userena_signup.activation_key | ||
response = self.client.get(reverse('userena_activate_retry', | ||
kwargs={'activation_key': old_key})) | ||
|
||
# We must reload the object from database to get the new key | ||
user = User.objects.get(email='[email protected]') | ||
self.assertContains(response, "Account re-activation succeded") | ||
|
||
self.failIfEqual(old_key, user.userena_signup.activation_key) | ||
user = User.objects.get(email='[email protected]') | ||
self.failUnless(not user.is_active) | ||
|
||
self.failUnlessEqual(len(mail.outbox), 2) | ||
self.assertEqual(mail.outbox[1].to, ['[email protected]']) | ||
self.assertTrue(mail.outbox[1].body.find("activate your account ")>-1) | ||
|
||
response = self.client.get(reverse('userena_activate', | ||
kwargs={'activation_key': user.userena_signup.activation_key})) | ||
self.assertRedirects(response, | ||
reverse('userena_profile_detail', kwargs={'username': user.username})) | ||
|
||
user = User.objects.get(email='[email protected]') | ||
self.failUnless(user.is_active) | ||
userena_settings.USERENA_ACTIVATION_RETRY = False | ||
|
||
def test_invalid_activation(self): | ||
""" | ||
A ``GET`` to the activation view with a wrong ``activation_key``. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters