Models
Below are the models of the accounts app.
EmailAddress
This model record the status of user emails registered. The fields are:
user: Relationship with CustomUser model from core app.
email: Email address of user. This field get the value of UNIQUE_EMAIL variable to set if will be unique.
verified: Boolean field to indicate if email was verified.
primary: Boolean field to indicate if email is primary.
It’s methods are:
str: Return a string to identify the model when is instanced.
get_or_create: Return an EmailAddress model instance with the first email registered of user. If there is not a record one is created. It receive as param an user instance.
get_not_primary: Return the first email address not primary of the user. It receive as param an user instance.
get_primary: Return the primary email address of the user. It receive as param an user instance.
set_as_primary: Set as primary an user email. If previously there is an other email as primary it is pass to false and set the new email as true.
send_confirmation: This method send an email confirmation and create a record in the EmailConformation model.
EmailConfirmation
This model record the key to validate an user emails. The fields are:
email_address: Relationship with EmailAddress model from accounts app.
created: To record create date.
sent: To record the date when last email verification was sent.
key: Random string used as verification unique token.
It’s methods are:
str: Return a string to identify the model when is instanced.
create: Method to create a new record into model. It does not require instantiation. It receive as params an instance of EmailAddress model and return an EmailConfirmation instance.
key_expired: Return a boolean if the key sent is expired or not.
confirm: Confirm the user email address. The method verify if the key is valid and set as verified and primary the email address in the model EmailAddress.
can_send_cooldown_period: Method that returns a boolean that indicates if an email can be sent, according to the creation time. It does not require instantiation. It receive as params the email address to verify.
time_to_resend_email: Method that returns the remaining time (in seconds) to resend the confirmation email. It does not need to be instantiated and receives the email to verify as a parameter.
delete_old_emails: Method that removes old EmailConfirmation records associated with an EmailAddress instance.
SocialApplication
Model that records integration data with some authentication provider, such as Google. It inherits the properties of the TimeStampedModel Model, which adds the created and updated fields, to record the creation and update date, respectively, of the records.
PROVIDERS: Tuple of providers available in the app.
provider: String that record the provider. Only allows values from the PROVIDERS tuple.
name: Provider name.
client_id: Stores the client id provided by the provider.
secret_key: Stores the secret_key id provided by the provider.
active: Boolean to active/deactive the record.
It’s methods are:
providers: Method that returns an object with the information from the PROVIDERS tuple. It does not require creating an instance of the model.
create_social_app: Method to record a new provider. It does not require to instantiate the model.
The extra configuration data, such as scope, urls, among others, must be set in the settings variable SOCIAL_ACCOUNT_PROVIDERS