This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_reset_password_token(self): | |
serializer = URLSafeTimedSerializer(current_app.config["SECRET_KEY"]) | |
return serializer.dumps(self.email, salt=self.password_hash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reset_password_email_html_content = """ | |
<p>Hello,</p> | |
<p>You are receiving this email because you requested a password reset for your account.</p> | |
<p> | |
To reset your password | |
<a href="{{ reset_password_url }}">click here</a>. | |
</p> | |
<p> | |
Alternatively, you can paste the following link in your browser's address bar: <br> | |
{{ reset_password_url }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import render_template_string | |
from flask_mailman import EmailMessage | |
from app.templates.auth.reset_password_email_content import ( | |
reset_password_email_html_content | |
) | |
def send_reset_password_email(user): | |
reset_password_url = url_for( | |
"auth.reset_password", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="post" novalidate> | |
{{ form.hidden_tag() }} | |
<p> | |
{{ form.email.label }}<br> | |
{{ form.email(size=32) }} | |
{% for error in form.email.errors %} | |
<p style="color: red;">{{ error }}</p> | |
{% endfor %} | |
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_wtf import FlaskForm | |
from wtforms import StringField, SubmitField | |
from wtforms.validators import DataRequired, Email | |
class ResetPasswordRequestForm(FlaskForm): | |
email = StringField("Email", validators=[DataRequired(), Email()]) | |
submit = SubmitField("Request Password Reset") |