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