From dd4fcdfe208c22db290cfabd29bf8c42698c11e4 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 8 Jul 2019 11:04:52 +0200 Subject: [PATCH] Add password reset request view. --- app/auth/views.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/auth/views.py b/app/auth/views.py index 5eef5868..b2e6ba68 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -1,7 +1,8 @@ from flask import flash, redirect, render_template, request, url_for from flask_login import login_required, login_user, logout_user from . import auth -from .forms import LoginForm +from .forms import LoginForm, PasswordResetRequestForm +from ..email import send_email from ..models import User @@ -31,3 +32,18 @@ def logout(): @auth.route('/register', methods=['GET', 'POST']) def register(): return render_template('auth/register.html.j2') + + +@auth.route('/reset', methods=['GET', 'POST']) +def password_reset_request(): + form = PasswordResetRequestForm() + if form.validate_on_submit(): + user = User.query.filter_by(email=form.email.data.lower()).first() + if user: + token = user.generate_reset_token() + send_email(user.email, 'Reset Your Password', + 'auth/email/reset_password', + user=user, token=token) + flash('An email with instructions to reset your password has been ' + 'sent to you.') + return redirect(url_for('auth.login'))