Пример #1
0
def _validate_email_change(user, data, field_errors):
    # If user has requested to change email, we must call the multi-step process to handle this.
    # It is not handled by the serializer (which considers email to be read-only).
    if "email" not in data:
        return

    if not settings.FEATURES['ALLOW_EMAIL_ADDRESS_CHANGE']:
        raise AccountUpdateError(
            u"Email address changes have been disabled by the site operators.")

    new_email = data["email"]
    try:
        student_views.validate_new_email(user, new_email)
    except ValueError as err:
        field_errors["email"] = {
            "developer_message":
            u"Error thrown from validate_new_email: '{}'".format(
                text_type(err)),
            "user_message":
            text_type(err)
        }
        return

    # Don't process with sending email to given new email, if it is already associated with
    # an account. User must see same success message with no error.
    # This is so that this endpoint cannot be used to determine if an email is valid or not.
    if email_exists_or_retired(new_email):
        del data["email"]
Пример #2
0
 def do_email_validation(self, email):
     """
     Executes validate_new_secondary_email, returning any resulting error message.
     """
     try:
         validate_new_email(self.request.user, email)
     except ValueError as err:
         return text_type(err)