Generalized app for two-step verification
Project description
Generalized app for two-step verification.
Supports Python 2.7, 3.5, 3.6, 3.7; Django 1.8 and Django 1.11.
Installation
Install the library, for instance with pip:
pip install django-verification
Add the library to your INSTALLED_APPS of an exiting project:
INSTALLED_APPS += ['verification']
Add the tables to the existing project:
python manage.py migrate verification
Upgrade
To 0.4.1 (needs Django 1.7+):
python manage.py migrate --fake verification 0001_initial
Demo
Copy the entire django-verification directory somewhere, set up and enter a virtualenv, then provided you are on some Un*x:
make demo
This’ll automatically make a user “admin” with the password “demo”.
The demo should now be running on http://127.0.0.1/
Running make demo again will erase the database from the previous run.
Tests
To run the tests, first install the testing-requirements:
pip install -r requirements/test.txt
then run the tests with:
make test APP=verification
Usage
Create a KeyGroup. KeyGroups hold the config for your Keys, so you might want to make fixtures of them.
from verification.models import KeyGroup
keygroup = KeyGroup(
name='activate_account', # Unique
generator='sha1', # See verification.generators
)
Create a Key on some event, for instance when a user clicks a button:
from verification.models import Key
Key.generate(group=keygroup)
Set Key.send_func to some callable:
from django.core.mail import send_mail
# In this minimal example, the contents of the email is created earlier
def email_key(recipient, content):
subject = "Activate account on FooBlog"
recipient = ''.join(recipient.strip().split())
# Use any kind of messaging-system here
send_mail(subject, content, 'noreply@example.com', [recipient])
key.send_func = email_key
Choose the claim-view, make the content of the email, send it with key.send_key():
from django.core.urlresolvers import reverse
activate_url = reverse('verification-claim-post-url',
kwargs={'key': key, 'group': key.group})
content = "Click on %s to activate your account on FooBlog!" % activate_url
recipient = 'john.oe@example.com'
key.send_key(recipient, content)
Hook the key_claimed-signal in order to do something after the key is claimed:
from django.dispatch import receiver
from verification.signals import key_claimed
@receiver(key_claimed)
def user_created_key_claimed(sender, **kwargs):
claimant = kwargs['claimant']
claimant.is_active = True
claimant.save()
- Version:
0.5.2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-verification-0.5.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 845c6fc82796544e17b6456a88dda745fe2454d38992c08bbef0fe4612562b45 |
|
MD5 | 377fd2747d3af5dcf08aef847ff695b8 |
|
BLAKE2b-256 | fb3d274a09d80869d38d77887742d65a2bb86ece26eb80e268212e97dadc439a |
Hashes for django_verification-0.5.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd0e63d96e1c638c8b61e38fcb926340a8b9e76374e17a7ae32efb915cadaa55 |
|
MD5 | 2fa4e1963ee52737f0879392d56f5099 |
|
BLAKE2b-256 | 7bfd67cb10c8a54c9770dc4ee0a964baec3d2db3d9d6d30d7a7afd77e8cfeeb2 |