registration.backends.default package

Module contents

class registration.backends.default.DefaultRegistrationBackend[source]

Bases: registration.backends.base.RegistrationBackendBase

Default registration backend class

A registration backend which floows a simple workflow:

  1. User sigs up, inactive account with unusable password is created.
  2. Inspector accept or reject the account registration.
  3. Email is sent to user with/without activation link (without when rejected)
  4. User clicks activation link, enter password, account is now active

Using this backend requires that

  • registration be listed in the INSTALLED_APPS settings (since this backend makes use of models defined in this application).
  • django.contrib.admin be listed in the INSTALLED_APPS settings
  • The setting ACCOUNT_ACTIVATION_DAYS be supplied, specifying (as an integer) the number of days from acceptance during which a user may activate their account (after that period expires, activation will be disallowed). Default is 7
  • The creation of the templates
    • registration/registration_email.txt
    • registration/registration_email_subject.txt
    • registration/acceptance_email.txt
    • registration/acceptance_email_subject.txt
    • registration/rejection_email.txt
    • registration/rejection_email_subject.txt
    • registration/activation_email.txt
    • registration/activation_email_subject.txt

Additinally, registration can be temporarily closed by adding the setting REGISTRATION_OPEN and setting it to False. Omitting this setting, or setting it to True, will be imterpreted as meaning that registration is currently open and permitted.

Internally, this is accomplished via storing an activation key in an instance of registration.models.RegistrationProfile. See that model and its custom manager for full documentation of its fields and supported operations.

accept(profile, request, send_email=None, message=None, force=False)[source]

accept the account registration of profile

Given a profile, accept account registration, which will set inspection status of profile to accepted and generate new activation key of profile.

An email will be sent to the supplied email address; The email will be rendered using two templates. See the documentation for RegistrationProfile.send_acceptance_email() for information about these templates and the contexts provided to them.

If REGISTRATION_acceptance_EMAIL of settings is None, no acceptance email will be sent.

After successful acceptance, the signal registration.signals.user_accepted will be sent, with the newly accepted User as the keyword argument uesr, the RegistrationProfile of the User as the keyword argument profile and the class of this backend as the sender

activate(activation_key, request, password=None, send_email=None, message=None, no_profile_delete=False)[source]

activate user with activation_key and password

Given an activation key, password, look up and activate the user account corresponding to that key (if possible) and set its password.

If password is not given, password will be generated

An email will be sent to the supplied email address; The email will be rendered using two templates. See the documentation for RegistrationProfile.send_activation_email() for information about these templates and the contexts provided to them.

If REGISTRATION_ACTIVATION_EMAIL of settings is None, no activation email will be sent.

After successful activation, the signal registration.signals.user_activated will be sent, with the newly activated User as the keyword argument uesr, the password of the User as the keyword argument password, whether the password has generated or not as the keyword argument is_generated and the class of this backend as the sender

get_activation_complete_url(user)[source]

Return a url to redirect to after successful user activation

get_activation_form_class()[source]

Return the default form class used for user activation

get_registration_closed_url()[source]

Return a url to redirect to if registration is closed

get_registration_complete_url(user)[source]

Return a url to redirect to after successful user registration

get_registration_form_class()[source]

Return the default form class used for user registration

get_supplement_class()[source]

Return the current registration supplement class

get_supplement_form_class()[source]

Return the default form class used for user registration supplement

register(username, email, request, supplement=None, send_email=None)[source]

register new user with username and email

Given a username, email address, register a new user account, which will initially be inactive and has unusable password.

Along with the new User object, a new registration.models.RegistrationProfile will be created, tied to that User, containing the inspection status and activation key which will be used for this account (activation key is not generated untill its inspection status is set to accepted)

An email will be sent to the supplied email address; The email will be rendered using two templates. See the documentation for RegistrationProfile.send_registration_email() for information about these templates and the contexts provided to them.

If REGISTRATION_REGISTRATION_EMAIL of settings is None, no registration email will be sent.

After the User and RegistrationProfile are created and the registration email is sent, the signal registration.signals.user_registered will be sent, with the new User as the keyword argument user, the RegistrationProfile of the new User as the keyword argument profile and the class of this backend as the sender.

registration_allowed()[source]

Indicate whether account registration is currently permitted, based on the value of the setting REGISTRATION_OEPN. This is determined as follows:

  • If REGISTRATION_OPEN is not specified in settings, or is set to True, registration is permitted.
  • If REGISTRATION_OPEN is both specified and set to False, registration is not permitted.
reject(profile, request, send_email=None, message=None)[source]

reject the account registration of profile

Given a profile, reject account registration, which will set inspection status of profile to rejected and delete activation key of profile if exists.

An email will be sent to the supplied email address; The email will be rendered using two templates. See the documentation for RegistrationProfile.send_rejection_email() for information about these templates and the contexts provided to them.

If REGISTRATION_REJECTION_EMAIL of settings is None, no rejection email will be sent.

After successful rejection, the signal registration.signals.user_rejected will be sent, with the newly rejected User as the keyword argument uesr, the RegistrationProfile of the User as the keyword argument profile and the class of this backend as the sender