beat.web.ui.registration.models module¶
-
class
beat.web.ui.registration.models.RegistrationManager[source]¶ Bases:
django.db.models.manager.ManagerCustom manager for the
RegistrationProfilemodel.The methods defined here provide shortcuts for account creation and activation (including generation and emailing of activation keys), and for cleaning out expired inactive accounts.
-
activate_user(activation_key, request)[source]¶ Validate an activation key and activate the corresponding
Userif valid.If the key is valid and has not expired, return the
Userafter activating.If the key is not valid or has expired, return
False.If the key is valid but the
Useris already active, returnFalse.To prevent reactivation of an account which has been deactivated by site administrators, the activation key is reset to the string constant
RegistrationProfile.ACTIVATEDafter successful activation.To execute customized logic when a
Useris activated, connect a function to the signalregistration.signals.user_activated; this signal will be sent (with theUseras the value of the keyword argumentuser) after a successful activation.
-
create_inactive_user(request, username, first_name, last_name, password, email, send_email=True)[source]¶ Create a new, inactive
User, generate aRegistrationProfileand email its activation key to theUser, returning the newUser.To disable the email, call with
send_email=False.The activation email will make use of two templates:
registration/activation_email_subject.txtThis template will be used for the subject line of the email. It receives one context variable,
site, which is the currently-activedjango.contrib.sites.models.Siteinstance. Because it is used as the subject line of an email, this template’s output must be only a single line of text; output longer than one line will be forcibly joined into only a single line.registration/activation_email.txtThis template will be used for the body of the email. It will receive three context variables:
activation_keywill be the user’s activation key (for use in constructing a URL to activate the account),expiration_dayswill be the number of days for which the key will be valid andsitewill be the currently-activedjango.contrib.sites.models.Siteinstance.
To execute customized logic once the new
Userhas been created, connect a function to the signalregistration.signals.user_registered; this signal will be sent (with the newUseras the value of the keyword argumentuser) after theUserandRegistrationProfilehave been created, and the email (if any) has been sent..
-
create_profile(user)[source]¶ Create a
RegistrationProfilefor a givenUser, and return theRegistrationProfile.The activation key for the
RegistrationProfilewill be a SHA1 hash, generated from a combination of theUser’s username and a random salt.
-
delete_expired_users()[source]¶ Remove expired instances of
RegistrationProfileand their associated ``User``s.Accounts to be deleted are identified by searching for instances of
RegistrationProfilewith expired activation keys, and then checking to see if their associatedUserinstances have the fieldis_activeset toFalse; anyUserwho is both inactive and has an expired activation key will be deleted.It is recommended that this method be executed regularly as part of your routine site maintenance; this application provides a custom management command which will call this method, accessible as
manage.py cleanupregistration.Regularly clearing out accounts which have never been activated serves two useful purposes:
It alleviates the ocasional need to reset a
RegistrationProfileand/or re-send an activation email when a user does not receive or does not act upon the initial activation email; since the account will be deleted, the user will be able to simply re-register and receive a new activation key.It prevents the possibility of a malicious user registering one or more accounts and never activating them (thus denying the use of those usernames to anyone else); since those accounts will be deleted, the usernames will become available for use again.
If you have a troublesome
Userand wish to disable their account while keeping it in the database, simply delete the associatedRegistrationProfile; an inactiveUserwhich does not have an associatedRegistrationProfilewill not be deleted.
-
-
class
beat.web.ui.registration.models.RegistrationProfile(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelA simple profile which stores an activation key for use during user account registration.
Generally, you will not want to interact directly with instances of this model; the provided manager includes methods for creating and activating new accounts, as well as for cleaning out accounts which have never been activated.
While it is possible to use this model as the value of the
AUTH_PROFILE_MODULEsetting, it’s not recommended that you do so. This model’s sole purpose is to store data temporarily during account registration and activation.-
ACTIVATED= 'ALREADY_ACTIVATED'¶
-
user¶ Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
-
activation_key¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <beat.web.ui.registration.models.RegistrationManager object>¶
-
activation_key_expired()[source]¶ Determine whether this
RegistrationProfile’s activation key has expired, returning a boolean –Trueif the key has expired.Key expiration is determined by a two-step process:
If the user has already activated, the key will have been reset to the string constant
ACTIVATED. Re-activating is not permitted, and so this method returnsTruein this case.Otherwise, the date the user signed up is incremented by the number of days specified in the setting
ACCOUNT_ACTIVATION_DAYS(which should be the number of days after signup during which a user is allowed to activate their account); if the result is less than or equal to the current date, the key has expired and this method returnsTrue.
-
exception
DoesNotExist¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
user_id¶
-
-
class
beat.web.ui.registration.models.PreregistrationProfile(id, first_name, last_name, email)[source]¶ Bases:
django.db.models.base.Model-
first_name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
last_name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
email¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
DoesNotExist¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-