Package: django-simple-email-confirmation
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 theUserUsers have one primary email address stored on theUsermodel, and have N secondary emails stored inEmailAddressobjectsUsers have N email addresses stored inEmailAddressobjects.ExamplesCreate a new User, confirm their email:fromdjango.core.mailimportsend_mail# ...email='original@here.com'user=User.objects.create_user(email,email=email)user.is_confirmed# Falsesend_mail(email,'Use%sto confirm your email'%user.confirmation_key)# User gets email, passes the confirmation_key back to your serveruser.confirm_email(user.confirmation_key)user.is_confirmed# TrueAdd 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_emailinuser.unconfirmed_emails# Truesend_mail(new_email,'Use%sto confirm your new email'%confirmation_key)# User gets email, passes the confirmation_key back to your serveruser.confirm_email(confirmation_key)new_emailinuser.confirmed_emails# Trueuser.set_primary_email(new_email)user.email# newaddr@nowhere.comInstallationFrompypiusingpip:pipinstalldjango-simple-email-confirmationAddsimple_email_confirmationto yoursettings.INSTALLED_APPS:INSTALLED_APPS=(...'simple_email_confirmation',...)Add the provided mixin to yourdjango 1.5+ custom user model:fromdjango.contrib.auth.modelsimportAbstractUserfromsimple_email_confirmation.modelsimportSimpleEmailConfirmationUserMixinclassUser(SimpleEmailConfirmationUserMixin,AbstractUser):passNote: you don’t strictly have to do this final step. Without this, you won’t have the nice helper functions and properties on yourUserobjects but the remainder of the app should function fine.Change default settings (optional):By default, keys don’t expire. If you want them to, setsettings.SIMPLE_EMAIL_CONFIRMATION_PERIODto a timedelta.fromdatetimeimporttimedeltaEMAIL_CONFIRMATION_PERIOD_DAYS=7SIMPLE_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, setsettings.SIMPLE_EMAIL_CONFIRMATION_AUTO_ADDto False.SIMPLE_EMAIL_CONFIRMATION_AUTO_ADD=FalseBy default, a length of keys is 12. If you want to change it, setsettings.SIMPLE_EMAIL_CONFIRMATION_KEY_LENGTHto integer value (maximum 40).SIMPLE_EMAIL_CONFIRMATION_KEY_LENGTH=16You 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, setsettings.SIMPLE_EMAIL_CONFIRMATION_EMAIL_ADDRESS_MODELto 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'Migrating0.23 to 1.0A number of backwards incompatible changes are included in the 1.0 release.Signal arguments have been refactored. Now, theemail_confirmed,unconfirmed_email_created, andprimary_email_changedsignals send the user class as thesenderargument and include the user instance as an additionaluserargument. You can update your code as follows:@receiver(email_confirmed)deflistener(sender,user,email,**kwargs):pass@receiver(unconfirmed_email_created)deflistener(sender,user,email,**kwargs):pass@receiver(primary_email_changed)deflistener(sender,user,old_email,new_email,**kwargs):passPython/Django supported versionsPython: 2.7, 3.4, 3.5 and 3.6Django: 1.8 to 2.0Running the TestsInstalltoxandcoveragepipinstalltoxcoverageFrom the repository root, runtoxtox-ecoverageIt’s that simple.Found a Bug?To file a bug or submit a patch, please head over todjango-simple-email-confirmation on github.CreditsOriginally adapted fromPinax’s django-email-confirmation, which was originally adapted fromJames Tauber’s django-email-confirmation.