Skip to main content

Simple email confirmation for django.

Project description

https://img.shields.io/travis/mfogel/django-simple-email-confirmation/develop.svg https://img.shields.io/coveralls/mfogel/django-simple-email-confirmation/develop.svg https://img.shields.io/pypi/dm/django-simple-email-confirmation.svg

A Django app providing simple email confirmation.

This app can be used to support three different ways of organizing your Users their email address(es). Each email address can be in a confirmed/unconfirmed state.

  • Users have one email address that is stored on the User

  • Users have one primary email address stored on the User model, and have N secondary emails stored in EmailAddress objects

  • Users have N email addresses stored in EmailAddress objects.

Examples

Create a new User, confirm their email:

from django.core.mail import send_mail
# ...

email = 'original@here.com'
user = User.objects.create_user(email, email=email)
user.is_confirmed # False

send_mail(email, 'Use %s to confirm your email' % user.confirmation_key)
# User gets email, passes the confirmation_key back to your server

user.confirm_email(user.confirmation_key)
user.is_confirmed # True

Add another email to an existing User, confirm it, then set it as their primary.

new_email = 'newaddr@nowhere.com'
confirmation_key = user.add_unconfirmed_email(new_email)
new_email in user.unconfirmed_emails # True

send_mail(new_email, 'Use %s to confirm your new email' % confirmation_key)
# User gets email, passes the confirmation_key back to your server

user.confirm_email(confirmation_key)
new_email in user.confirmed_emails # True

user.set_primary_email(new_email)
user.email # newaddr@nowhere.com

Installation

  1. From pypi using pip:

    pip install django-simple-email-confirmation
  2. Add simple_email_confirmation to your settings.INSTALLED_APPS:

    INSTALLED_APPS = (
        ...
        'simple_email_confirmation',
        ...
    )
  3. Add the provided mixin to your django 1.5+ custom user model:

    from django.contrib.auth.models import AbstractUser
    from simple_email_confirmation.models import SimpleEmailConfirmationUserMixin
    
    class User(SimpleEmailConfirmationUserMixin, AbstractUser):
        pass

    Note: you don’t strictly have to do this final step. Without this, you won’t have the nice helper functions and properties on your User objects but the remainder of the app should function fine.

  4. Change default settings (optional):

    By default, keys don’t expire. If you want them to, set settings.SIMPLE_EMAIL_CONFIRMATION_PERIOD to a timedelta.

    from datetime import timedelta
    
    EMAIL_CONFIRMATION_PERIOD_DAYS = 7
    SIMPLE_EMAIL_CONFIRMATION_PERIOD = timedelta(days=EMAIL_CONFIRMATION_PERIOD_DAYS)

    By default, auto-add unconfirmed EmailAddress objects for new Users. If you want to change this behaviour, set settings.SIMPLE_EMAIL_CONFIRMATION_AUTO_ADD to False.

    SIMPLE_EMAIL_CONFIRMATION_AUTO_ADD = False

    By default, a length of keys is 12. If you want to change it, set settings.SIMPLE_EMAIL_CONFIRMATION_KEY_LENGTH to integer value (maximum 40).

    SIMPLE_EMAIL_CONFIRMATION_KEY_LENGTH = 16

    You are able to override the EmailAddress model provided with this app. This works in a similar fashion as Django’s custom user model and allows you to add fields to the EmailAddress model, such as a uuid, or define your own model completely. To set a custom email address model, set settings.SIMPLE_EMAIL_CONFIRMATION_EMAIL_ADDRESS_MODEL to the model you would like to use in the <app_label>.<model_name> fashion.

    An admin interface is included with simple email confirmation. Although, it is designed to work with the EmailAddress provided. Functionality with the admin cannot be guaranteed when a custom model is used so it is recommended you provide your own admin definition.

    Note for existing apps that already use the provided model:

    Similar to Django’s custom user model, migrating a custom email address model after the default one is already migrated is not supported and could have unforeseen side effects. The recommendation is to use a custom model from the beginning of development.

    SIMPLE_EMAIL_CONFIRMATION_EMAIL_ADDRESS_MODEL = 'yourapp.EmailAddress'

Migrating

0.23 to 1.0

A number of backwards incompatible changes are included in the 1.0 release.

  • Signal arguments have been refactored. Now, the email_confirmed, unconfirmed_email_created, and primary_email_changed signals send the user class as the sender argument and include the user instance as an additional user argument. You can update your code as follows:

    @receiver(email_confirmed)
    def listener(sender, user, email, **kwargs):
        pass
    
    @receiver(unconfirmed_email_created)
    def listener(sender, user, email, **kwargs):
        pass
    
    @receiver(primary_email_changed)
    def listener(sender, user, old_email, new_email, **kwargs):
        pass

Python/Django supported versions

  • Python: 2.7, 3.4, 3.5 and 3.6

  • Django: 1.8 to 2.0

Running the Tests

  1. Install tox and coverage

    pip install tox coverage
  2. From the repository root, run

    tox
    tox -e coverage

    It’s that simple.

Found a Bug?

To file a bug or submit a patch, please head over to django-simple-email-confirmation on github.

Credits

Originally adapted from Pinax’s django-email-confirmation, which was originally adapted from James Tauber’s django-email-confirmation.

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-simple-email-confirmation-0.7.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-simple-email-confirmation-0.7.tar.gz.

File metadata

  • Download URL: django-simple-email-confirmation-0.7.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

File hashes

Hashes for django-simple-email-confirmation-0.7.tar.gz
Algorithm Hash digest
SHA256 de94efecd0acb1869c3b3bd25d1990f2724d038ad904cccc1a3e62e66e66035e
MD5 4246c718366467ac3890a1080c03ec3c
BLAKE2b-256 63ae4b9ef3855edad8030e6f1fcad815612d6978b162cdab8722fa2fee751d55

See more details on using hashes here.

File details

Details for the file django_simple_email_confirmation-0.7-py3-none-any.whl.

File metadata

  • Download URL: django_simple_email_confirmation-0.7-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

File hashes

Hashes for django_simple_email_confirmation-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c1223eb0e343571435d4fd8c27a1ae8593b18ae6c608a2fc27544941b1242ede
MD5 2cc02109bb8f474e81119c49cba2883c
BLAKE2b-256 b439ad6b30f9f84d1f5e76f2e55d407827a31d51539232038f6c68a586775647

See more details on using hashes here.

Supported by

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