Skip to content

Instantly share code, notes, and snippets.

@pcustic
pcustic / models.py
Created January 16, 2024 12:03
app/models.py
def generate_reset_password_token(self):
serializer = URLSafeTimedSerializer(current_app.config["SECRET_KEY"])
return serializer.dumps(self.email, salt=self.password_hash)
@pcustic
pcustic / reset_password_email_content.py
Created January 16, 2024 12:01
app/templates/auth/reset_password_email_content.py
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 }}
@pcustic
pcustic / routes.py
Created January 16, 2024 12:00
add to app/auth/routes.py
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",
@pcustic
pcustic / reset_password_request.html
Created January 16, 2024 11:59
auth/reset_password_request.html
<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>
@pcustic
pcustic / routes.py
Last active January 16, 2024 12:06
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
@pcustic
pcustic / forms.py
Created January 16, 2024 11:25
app/auth/forms.py
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")