mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 13:19:49 -04:00
Fix for forgot my password.
This commit is contained in:
@@ -52,10 +52,9 @@ def is_email_unique(email_address):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def request_password_reset(email):
|
def request_password_reset(user):
|
||||||
user = get_user_by_email(email)
|
|
||||||
user.state = 'request_password_reset'
|
user.state = 'request_password_reset'
|
||||||
# TODO update user
|
user_api_client.update_user(user)
|
||||||
|
|
||||||
|
|
||||||
def send_verify_code(user_id, code_type, to=None):
|
def send_verify_code(user_id, code_type, to=None):
|
||||||
|
|||||||
@@ -221,8 +221,17 @@ class TemplateForm(Form):
|
|||||||
|
|
||||||
|
|
||||||
class ForgotPasswordForm(Form):
|
class ForgotPasswordForm(Form):
|
||||||
|
|
||||||
|
def __init__(self, user_email_exists_func, *args, **kwargs):
|
||||||
|
self._user_email_exists_func = user_email_exists_func
|
||||||
|
super(ForgotPasswordForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
email_address = email_address()
|
email_address = email_address()
|
||||||
|
|
||||||
|
def validate_email_address(self, field):
|
||||||
|
if not self._user_email_exists_func(field.data):
|
||||||
|
raise ValidationError('The email is not registered on our system')
|
||||||
|
|
||||||
|
|
||||||
class NewPasswordForm(Form):
|
class NewPasswordForm(Form):
|
||||||
new_password = password()
|
new_password = password()
|
||||||
|
|||||||
@@ -7,13 +7,15 @@ from app.notify_client.sender import send_change_password_email
|
|||||||
|
|
||||||
@main.route('/forgot-password', methods=['GET', 'POST'])
|
@main.route('/forgot-password', methods=['GET', 'POST'])
|
||||||
def forgot_password():
|
def forgot_password():
|
||||||
form = ForgotPasswordForm()
|
|
||||||
|
def _email_exists(email):
|
||||||
|
return not users_dao.is_email_unique(email)
|
||||||
|
|
||||||
|
form = ForgotPasswordForm(_email_exists)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
if users_dao.get_user_by_email(form.email_address.data):
|
user = users_dao.get_user_by_email(form.email_address.data)
|
||||||
users_dao.request_password_reset(form.email_address.data)
|
users_dao.request_password_reset(user)
|
||||||
send_change_password_email(form.email_address.data)
|
send_change_password_email(form.email_address.data)
|
||||||
return render_template('views/password-reset-sent.html')
|
return render_template('views/password-reset-sent.html')
|
||||||
else:
|
|
||||||
current_app.logger.info('The email address used does not exist.')
|
return render_template('views/forgot-password.html', form=form)
|
||||||
else:
|
|
||||||
return render_template('views/forgot-password.html', form=form)
|
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ def user_profile_password():
|
|||||||
|
|
||||||
# Validate password for form
|
# Validate password for form
|
||||||
def _check_password(pwd):
|
def _check_password(pwd):
|
||||||
return verify_password(current_user, pwd)
|
return verify_password(current_user.id, pwd)
|
||||||
form = ChangePasswordForm(_check_password)
|
form = ChangePasswordForm(_check_password)
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
|||||||
@@ -203,7 +203,8 @@ def test_should_redirect_after_mobile_number_authenticate(app_,
|
|||||||
api_user_active,
|
api_user_active,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_verify_password):
|
mock_verify_password,
|
||||||
|
mock_send_verify_code):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
|
|||||||
Reference in New Issue
Block a user