Simple email confirmation for django.
Project description
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
-
pip install django-simple-email-confirmation
Add simple_email_confirmation to your settings.INSTALLED_APPS:
INSTALLED_APPS = ( ... 'simple_email_confirmation', ... )
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.
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
Python/Django supported versions
Python: 2.7, 3.4, 3.5 and 3.6
Django: 1.8 to 2.0
Running the Tests
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
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
File details
Details for the file django-simple-email-confirmation-0.3.tar.gz
.
File metadata
- Download URL: django-simple-email-confirmation-0.3.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd1f26700bba92ec5cda0c68c0f4f21ed1af3d632e32baf1ab31bcecc05899e1 |
|
MD5 | eddafd76a18792d6ba58d6b78158287b |
|
BLAKE2b-256 | 249a4c85c1395c44eca0bb11a78ba2688c5201f726014d6b2d4d0084277ab2df |