mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Removed exceptions, found a better way to handle them.
Refactored the forms so that fields like email_address can be used in multiple forms. Refactored form validation so that a query function is passed into the form to be run, this way the form is not exposed to the dao layer and the query is more efficient. This PR still requires some frontend attention. Will work with Chris to update the templates.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import (render_template, url_for, redirect, flash, current_app)
|
||||
from flask import (render_template, url_for, redirect, flash)
|
||||
|
||||
from app.main import main
|
||||
from app.main.dao import users_dao
|
||||
@@ -10,20 +8,18 @@ from app.main.views import send_sms_code, check_token
|
||||
|
||||
@main.route('/new-password/<path:token>', methods=['GET', 'POST'])
|
||||
def new_password(token):
|
||||
email_address = check_token(token)
|
||||
if not email_address:
|
||||
flash('The token we sent you has expired. Enter your email address to try again.')
|
||||
return redirect(url_for('.forgot_password'))
|
||||
|
||||
user = users_dao.get_user_by_email(email_address=email_address.decode('utf-8'))
|
||||
|
||||
form = NewPasswordForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
email_address = check_token(token)
|
||||
if email_address:
|
||||
user = users_dao.update_password(email_address.decode('utf-8'), form.new_password.data)
|
||||
send_sms_code(user.id, user.mobile_number)
|
||||
return redirect(url_for('main.two_factor'))
|
||||
else:
|
||||
flash('expired token request again')
|
||||
current_app.logger.info('we got here')
|
||||
return redirect(url_for('.forgot_password'))
|
||||
users_dao.update_password(user, form.new_password.data)
|
||||
send_sms_code(user.id, user.mobile_number)
|
||||
return redirect(url_for('main.two_factor'))
|
||||
else:
|
||||
return render_template('views/new-password.html', toke=token, form=form)
|
||||
|
||||
|
||||
def valid_token(token):
|
||||
return token and datetime.now() <= token.expiry_date
|
||||
return render_template('views/new-password.html', token=token, form=form, user=user)
|
||||
|
||||
Reference in New Issue
Block a user