Re-implement forgot password

This commit is contained in:
Rebecca Law
2016-03-07 18:18:52 +00:00
parent 8a46031203
commit 3e969b3640
8 changed files with 105 additions and 96 deletions

View File

@@ -1,25 +1,22 @@
from flask import (
render_template,
flash
)
from notifications_python_client.errors import HTTPError
from app.main import main
from app.main.dao import users_dao
from app.main.forms import ForgotPasswordForm
from app.notify_client.sender import send_change_password_email
from app import user_api_client
@main.route('/forgot-password', methods=['GET', 'POST'])
def forgot_password():
form = ForgotPasswordForm()
if form.validate_on_submit():
if not users_dao.is_email_unique(form.email_address.data):
user = users_dao.get_user_by_email(form.email_address.data)
users_dao.request_password_reset(user)
send_change_password_email(form.email_address.data)
return render_template('views/password-reset-sent.html')
else:
return render_template('views/password-reset-sent.html')
try:
user_api_client.send_reset_password_url(form.email_address.data)
except HTTPError as e:
if e.status_code != 404:
raise e
return render_template('views/password-reset-sent.html')
return render_template('views/forgot-password.html', form=form)