Models

EmailChange

class change_email.models.EmailChange(*args, **kwargs)

A model to temporarily store an email adress change request.

new_email

EmailField (Required)

The new email address that still needs to be confirmed.

Parameters:
  • error_messages – {u’unique’: u’%(model_name)s with this %(field_label)s already exists.’, u’invalid_choice’: u’Value %r is not a valid choice.’, u’null’: u’This field cannot be null.’, u’blank’: u’This field cannot be blank.’}
  • help_text – The new email address that still needs to be confirmed.
  • validators – [‘EmailValidator‘, ‘MaxLengthValidator‘]
  • verbose_name – new email address
date

DateTimeField (Automatically set when created)

The date and time the email address change was requested.

Parameters:
  • auto_now_add – True
  • blank – True
  • error_messages – {u’unique’: u’%(model_name)s with this %(field_label)s already exists.’, u’null’: u’This field cannot be null.’, u’invalid’: u”’%s’ value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format.”, u’invalid_choice’: u’Value %r is not a valid choice.’, u’invalid_date’: u”’%s’ value has the correct format (YYYY-MM-DD) but it is an invalid date.”, u’blank’: u’This field cannot be blank.’, u’invalid_datetime’: u”’%s’ value has the correct format (YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) but it is an invalid date/time.”}
  • help_text – The date and time the email address change was requested.
  • verbose_name – date
user

OneToOneField(‘User‘) (Required)

The user that has requested the email address change.

Parameters:
  • db_index – True
  • error_messages – {u’unique’: u’%(model_name)s with this %(field_label)s already exists.’, u’invalid_choice’: u’Value %r is not a valid choice.’, u’null’: u’This field cannot be null.’, ‘invalid’: u’Model %(model)s with pk %(pk)r does not exist.’, u’blank’: u’This field cannot be blank.’}
  • help_text – The user that has requested the email address change.
  • unique – True
  • verbose_name – user
site

ForeignKey(‘Site‘)

Parameters:
  • blank – True
  • db_index – True
  • error_messages – {u’unique’: u’%(model_name)s with this %(field_label)s already exists.’, u’invalid_choice’: u’Value %r is not a valid choice.’, u’null’: u’This field cannot be null.’, ‘invalid’: u’Model %(model)s with pk %(pk)r does not exist.’, u’blank’: u’This field cannot be blank.’}
  • null – True
  • verbose_name – site
Meta

get_latest_by = date

ordering = []

verbose_name = email address change request

verbose_name_plural = email address change requests

check_signature(signature)

Checks if

Parameters:signature (str) – The signature to check, as generated by make_signature().
Returns:True if the check was successfully completed, False otherwise.
Return type:bool
get_expiration_date(seconds=None)

Returns the expiration date of an EmailChange object by adding a given amount of seconds to it.

Parameters:seconds (int) – The number of seconds to calculate a datetime.timedelta object. Defaults to EMAIL_CHANGE_TIMEOUT.
Returns:A datetime object representing the expiration date.
Return type:datetime
has_expired(seconds=None)

Checks whether this request has already expired.

Parameters:seconds (int) – The number of seconds to calculate a datetime.timedelta object. Defaults to EMAIL_CHANGE_TIMEOUT.
Returns:True if the request has already expired, False otherwise.
Return type:bool
make_signature()

Generates a signature to use in one-time secret URL’s to confirm the email address change request.

Returns:A signature.
Return type:str
send_confirmation_mail(request)

An instance method to send a confirmation mail to the new email address.

The generation of a confirmation email will use three templates that can be set in each project’s settings:

  • EMAIL_CHANGE_HTML_EMAIL_TEMPLATE.
  • EMAIL_CHANGE_SUBJECT_EMAIL_TEMPLATE
  • EMAIL_CHANGE_TXT_EMAIL_TEMPLATE

These templates will receive the following context variables:

date
The date when the email address change was requested.
timeout_date
The date whe the request will expire.
current_site
An object representing the current site on which the user is logged in. Depending on whether django.contrib.sites is installed, this may be an instance of either django.contrib.sites.models.Site (if the sites application is installed) or django.contrib.sites.models.RequestSite (if not). Consult the documentation for the Django sites framework for details regarding these objects’ interfaces.
new_email
The new email address.
protocol
The protocol used to generate the confirmation URL, either HTTP or HTTPS. To use HTTPS set EMAIL_CHANGE_USE_HTTPS to True.
signature
The confirmation signature for the new email address.
user
The user that has requested the email address change.
Parameters:request (obj) – The request object.
verify_signature(signature)

Checks if the signature has been tampered with.

Parameters:signature (str) – The signature to check, as generated by make_signature().
Returns:True if the signature has not been tampered with, False otherwise. :rtype: bool