Files
notifications-admin/app/main/views/new_password.py
T

33 lines
1.2 KiB
Python
Raw Normal View History

2016-02-11 15:59:28 +00:00
from flask import (render_template, url_for, redirect, flash, session)
2016-01-05 17:52:09 +00:00
from app.main import main
from app.main.dao import users_dao
2016-01-06 17:37:07 +00:00
from app.main.forms import NewPasswordForm
from app.notify_client.sender import check_token
2016-01-05 17:52:09 +00:00
2016-01-06 17:37:07 +00:00
@main.route('/new-password/<path:token>', methods=['GET', 'POST'])
def new_password(token):
email_address = check_token(token)
if not email_address:
2016-01-08 16:47:34 +00:00
flash('The link in the email we sent you has expired. Enter your email address to resend.')
return redirect(url_for('.forgot_password'))
user = users_dao.get_user_by_email(email_address=email_address)
if user and user.state != 'request_password_reset':
flash('The link in the email we sent you has already been used.')
return redirect(url_for('.index'))
2016-01-06 17:37:07 +00:00
form = NewPasswordForm()
2016-01-06 17:37:07 +00:00
if form.validate_on_submit():
users_dao.send_verify_code(user.id, 'sms')
2016-01-27 16:30:33 +00:00
session['user_details'] = {
'id': user.id,
'email': user.email_address,
'password': form.new_password.data}
2016-02-11 15:59:28 +00:00
users_dao.activate_user(user)
return redirect(url_for('main.two_factor'))
2016-01-06 17:37:07 +00:00
else:
return render_template('views/new-password.html', token=token, form=form, user=user)