-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VerificationDevice model and Removal of 48hr email verification period (#1606)
- Loading branch information
1 parent
76495ef
commit 9a51a27
Showing
23 changed files
with
366 additions
and
69 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
78 changes: 78 additions & 0 deletions
78
cadasta/accounts/migrations/0007_phone_and_verification_device.py
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,78 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.7 on 2017-07-17 16:50 | ||
from __future__ import unicode_literals | ||
|
||
import accounts.models | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_otp.util | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0006_add_measurement_field'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='VerificationDevice', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(help_text='The human-readable name of this device.', max_length=64)), | ||
('confirmed', models.BooleanField(default=True, help_text='Is this device ready for use?')), | ||
('unverified_phone', models.CharField(max_length=16, unique=True)), | ||
('secret_key', models.CharField(default=accounts.models.default_key, help_text='Hex-encoded secret key to generate totp tokens.', max_length=40, unique=True, validators=[django_otp.util.hex_validator])), | ||
('last_verified_counter', models.BigIntegerField(default=-1, help_text='The counter value of the latest verified token.The next token must be at a higher counter value.It makes sure a token is used only once.')), | ||
('verified', models.BooleanField(default=False)), | ||
], | ||
options={ | ||
'verbose_name': 'Verification Device', | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaluser', | ||
name='verify_email_by', | ||
), | ||
migrations.RemoveField( | ||
model_name='user', | ||
name='verify_email_by', | ||
), | ||
migrations.AddField( | ||
model_name='historicaluser', | ||
name='phone', | ||
field=models.CharField(blank=True, db_index=True, default=None, max_length=16, null=True, verbose_name='phone number'), | ||
), | ||
migrations.AddField( | ||
model_name='historicaluser', | ||
name='phone_verified', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='phone', | ||
field=models.CharField(blank=True, default=None, max_length=16, null=True, unique=True, verbose_name='phone number'), | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='phone_verified', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name='historicaluser', | ||
name='email', | ||
field=models.EmailField(blank=True, db_index=True, default=None, max_length=254, null=True, verbose_name='email address'), | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='email', | ||
field=models.EmailField(blank=True, default=None, max_length=254, null=True, unique=True, verbose_name='email address'), | ||
), | ||
migrations.AddField( | ||
model_name='verificationdevice', | ||
name='user', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ class Meta: | |
|
||
username = factory.Sequence(lambda n: "testuser%s" % n) | ||
email = factory.Sequence(lambda n: "email_%[email protected]" % n) | ||
phone = factory.Sequence(lambda n: "+123456789%s" % n) | ||
password = '' | ||
|
||
@classmethod | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import random | ||
import pytest | ||
|
||
from core.tests.utils.cases import UserTestCase | ||
from core.messages import SANITIZE_ERROR | ||
|
@@ -7,7 +8,7 @@ | |
from django.http import HttpRequest | ||
from django.db import IntegrityError | ||
from allauth.account.models import EmailAddress | ||
from allauth.account.utils import send_email_confirmation | ||
|
||
from django.test import TestCase | ||
from django.utils.translation import gettext as _ | ||
|
||
|
@@ -390,15 +391,12 @@ def test_signup_with_released_email(self): | |
|
||
form = forms.ProfileForm(data, request=request, instance=user) | ||
form.save() | ||
with pytest.raises(EmailAddress.DoesNotExist): | ||
EmailAddress.objects.get(email="[email protected]") | ||
|
||
user = UserFactory.create(username='user2', | ||
email='[email protected]') | ||
try: | ||
send_email_confirmation(request, user) | ||
except IntegrityError: | ||
assert False | ||
else: | ||
assert True | ||
with pytest.raises(IntegrityError): | ||
user = UserFactory.create(username='user2', | ||
email='[email protected]') | ||
|
||
def test_update_email_with_incorrect_password(self): | ||
user = UserFactory.create(email='[email protected]', | ||
|
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 |
---|---|---|
|
@@ -8,29 +8,38 @@ | |
|
||
|
||
class UserManagerTest(UserTestCase, TestCase): | ||
def test_get_from_usernamel(self): | ||
def test_get_from_username(self): | ||
user = UserFactory.create() | ||
found = User.objects.get_from_username_or_email( | ||
found = User.objects.get_from_username_or_email_or_phone( | ||
identifier=user.username | ||
) | ||
|
||
assert found == user | ||
|
||
def test_get_from_email(self): | ||
user = UserFactory.create() | ||
found = User.objects.get_from_username_or_email(identifier=user.email) | ||
found = User.objects.get_from_username_or_email_or_phone( | ||
identifier=user.email) | ||
|
||
assert found == user | ||
|
||
def test_get_from_phone(self): | ||
user = UserFactory.create() | ||
found = User.objects.get_from_username_or_email_or_phone( | ||
identifier=user.phone | ||
) | ||
assert found == user | ||
|
||
def test_user_not_found(self): | ||
with raises(User.DoesNotExist): | ||
User.objects.get_from_username_or_email(identifier='username') | ||
User.objects.get_from_username_or_email_or_phone( | ||
identifier='username') | ||
|
||
def test_mulitple_users_found(self): | ||
UserFactory.create(username='[email protected]') | ||
UserFactory.create(email='[email protected]') | ||
|
||
with raises(User.MultipleObjectsReturned): | ||
User.objects.get_from_username_or_email( | ||
User.objects.get_from_username_or_email_or_phone( | ||
identifier='[email protected]' | ||
) |
Oops, something went wrong.