Skip to content

Instantly share code, notes, and snippets.

@pcustic
Last active January 16, 2024 12:06
Show Gist options
  • Save pcustic/b454fd87b91c112deb020665ab19083e to your computer and use it in GitHub Desktop.
Save pcustic/b454fd87b91c112deb020665ab19083e to your computer and use it in GitHub Desktop.
app/auth/routes.py
from flask import render_template, redirect, url_for, flash, render_template_string
from sqlalchemy import select
from flask_login import current_user
from app import db
from app.models import User
from app.auth import bp
from app.auth.forms import ResetPasswordRequestForm
@bp.route("/reset_password", methods=["GET", "POST"])
def reset_password_request():
if current_user.is_authenticated:
return redirect(url_for("main.index"))
form = ResetPasswordRequestForm()
if form.validate_on_submit():
user_select = select(User).where(User.email == form.email.data)
user = db.session.scalar(user_select)
if user:
send_reset_password_email(user)
flash(
"Instructions to reset your password were sent to your email address,"
" if it exists in our system."
)
return redirect(url_for("auth.reset_password_request"))
return render_template(
"auth/reset_password_request.html", title="Reset Password", form=form
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment