Skip to main content

Generalized app for two-step verification

Project description

Generalized app for two-step verification.

Supports Python 3.5, 3.6, 3.7; Django 1.11 and Django 2.2.

Versions prior to 1.0.0 support Python 2 and Django older than 1.11.

Installation

  1. Install the library, for instance with pip:

    pip install django-verification
  2. Add the library to your INSTALLED_APPS of an exiting project:

    INSTALLED_APPS += ['verification']
  3. 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:

1.1.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-verification-1.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_verification-1.1.0-py2.py3-none-any.whl (13.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-verification-1.1.0.tar.gz.

File metadata

  • Download URL: django-verification-1.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for django-verification-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7df37b552c8da9c9f763caa9b0c33d210993c3c8df0bda7e15890d9d70460a01
MD5 c798be5037a9c28fb17785d2f3caa73d
BLAKE2b-256 cf24521cc80d07bcb891f5582cb8a099fda40b8085429637490dce4bd79e928b

See more details on using hashes here.

File details

Details for the file django_verification-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_verification-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for django_verification-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e932974cce0fcc6b103b290b3bac5e83286e027d7c62ce0782b238a8b8bb89bf
MD5 25194d35caf7f716923eca109998a7fb
BLAKE2b-256 7829d7f53e18b49148154a5b1d5811ab93f0cb0da3ea2296dbc8424d289cd145

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page