Add password reset request handling to the account page
The next step in the password reset process (confirmation) continues to be handled by student.views.password_reset_confirm_wrapper, a custom wrapper around Django's password reset confirmation view.
This commit is contained in:
@@ -5,8 +5,11 @@ address, but does NOT include user profile information (i.e., demographic
|
||||
information and preferences).
|
||||
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.db import transaction, IntegrityError
|
||||
from django.core.validators import validate_email, validate_slug, ValidationError
|
||||
from django.contrib.auth.forms import PasswordResetForm
|
||||
|
||||
from user_api.models import User, UserProfile, Registration, PendingEmailChange
|
||||
from user_api.helpers import intercept_errors
|
||||
|
||||
@@ -300,6 +303,43 @@ def confirm_email_change(activation_key):
|
||||
return (old_email, new_email)
|
||||
|
||||
|
||||
@intercept_errors(AccountInternalError, ignore_errors=[AccountRequestError])
|
||||
def request_password_change(email, orig_host, is_secure):
|
||||
"""Email a single-use link for performing a password reset.
|
||||
|
||||
Users must confirm the password change before we update their information.
|
||||
|
||||
Args:
|
||||
email (string): An email address
|
||||
orig_host (string): An originating host, extracted from a request with get_host
|
||||
is_secure (Boolean): Whether the request was made with HTTPS
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
||||
Raises:
|
||||
AccountUserNotFound
|
||||
AccountRequestError
|
||||
|
||||
"""
|
||||
# Binding data to a form requires that the data be passed as a dictionary
|
||||
# to the Form class constructor.
|
||||
form = PasswordResetForm({'email': email})
|
||||
|
||||
# Validate that an active user exists with the given email address.
|
||||
if form.is_valid():
|
||||
# Generate a single-use link for performing a password reset
|
||||
# and email it to the user.
|
||||
form.save(
|
||||
from_email=settings.DEFAULT_FROM_EMAIL,
|
||||
domain_override=orig_host,
|
||||
use_https=is_secure
|
||||
)
|
||||
else:
|
||||
# No active user with the provided email address exists.
|
||||
raise AccountUserNotFound
|
||||
|
||||
|
||||
def _validate_username(username):
|
||||
"""Validate the username.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user