flask site buildout #2
@ -1,12 +1,17 @@
|
|||||||
|
from threading import Thread
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask_mail import Message
|
from flask_mail import Message
|
||||||
from app import mail, app
|
from app import mail, app
|
||||||
|
|
||||||
|
def send_async_email(app, msg):
|
||||||
|
with app.app_context():
|
||||||
|
mail.send(msg)
|
||||||
|
|
||||||
def send_email(subject, sender, recipients, text_body, html_body):
|
def send_email(subject, sender, recipients, text_body, html_body):
|
||||||
msg = Message(subject, sender=sender, recipients=recipients)
|
msg = Message(subject, sender=sender, recipients=recipients)
|
||||||
msg.body = text_body
|
msg.body = text_body
|
||||||
msg.html = html_body
|
msg.html = html_body
|
||||||
mail.send(msg)
|
Thread(target=send_async_email, args=(app, msg)).start()
|
||||||
|
|
||||||
def send_password_reset_email(user):
|
def send_password_reset_email(user):
|
||||||
token = user.get_reset_password_token()
|
token = user.get_reset_password_token()
|
||||||
|
@ -10,7 +10,7 @@ from app import db, login, app
|
|||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
|
|
||||||
#debug
|
#debug
|
||||||
import sys
|
#import sys
|
||||||
|
|
||||||
followers = sa.Table(
|
followers = sa.Table(
|
||||||
'followers',
|
'followers',
|
||||||
|
@ -10,7 +10,7 @@ from app.models import User, Post
|
|||||||
from app.email import send_password_reset_email
|
from app.email import send_password_reset_email
|
||||||
|
|
||||||
#debug:
|
#debug:
|
||||||
import sys
|
#import sys
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
@ -90,15 +90,12 @@ def register():
|
|||||||
@app.route('/reset_password/<token>', methods=['GET', 'POST'])
|
@app.route('/reset_password/<token>', methods=['GET', 'POST'])
|
||||||
def reset_password(token):
|
def reset_password(token):
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
print('rp user is authed', file=sys.stderr)
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
user = User.verify_reset_password_token(token)
|
user = User.verify_reset_password_token(token)
|
||||||
if not user:
|
if not user:
|
||||||
print('rp not user', file=sys.stderr)
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
form = ResetPasswordForm()
|
form = ResetPasswordForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
print('rp validated', file=sys.stderr)
|
|
||||||
user.set_password(form.password.data)
|
user.set_password(form.password.data)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Your password has been reset.')
|
flash('Your password has been reset.')
|
||||||
@ -175,14 +172,11 @@ def unfollow(username):
|
|||||||
@app.route('/reset_password_request', methods=['GET', 'POST'])
|
@app.route('/reset_password_request', methods=['GET', 'POST'])
|
||||||
def reset_password_request():
|
def reset_password_request():
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
print('rpr user is authed', file=sys.stderr)
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
form = ResetPasswordRequestForm()
|
form = ResetPasswordRequestForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
print('rpr form validated', file=sys.stderr)
|
|
||||||
user = db.session.scalar(sa.select(User).where(User.email == form.email.data))
|
user = db.session.scalar(sa.select(User).where(User.email == form.email.data))
|
||||||
if user:
|
if user:
|
||||||
print('rpr if user', file=sys.stderr)
|
|
||||||
send_password_reset_email(user)
|
send_password_reset_email(user)
|
||||||
flash('Password reset sent.')
|
flash('Password reset sent.')
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<header>
|
||||||
blog:
|
<nav>
|
||||||
<a href="{{ url_for('index') }}">home</a>
|
<a href="{{ url_for('index') }}">home</a>
|
||||||
<a href="{{ url_for('explore') }}">explore</a>
|
<a href="{{ url_for('explore') }}">explore</a>
|
||||||
{% if current_user.is_anonymous %}
|
{% if current_user.is_anonymous %}
|
||||||
@ -20,7 +20,10 @@
|
|||||||
<a href="{{ url_for('logout') }}">logout</a>
|
<a href="{{ url_for('logout') }}">logout</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</nav>
|
||||||
|
<h1>oily.dad</h1>
|
||||||
|
<h4>destroy me</h4>
|
||||||
|
</header>
|
||||||
<hr>
|
<hr>
|
||||||
{% with messages = get_flashed_messages() %}
|
{% with messages = get_flashed_messages() %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
|
Loading…
Reference in New Issue
Block a user