added connection status macro and background task scheduling
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
from flask import render_template, redirect, request, url_for, flash
|
||||
from flask_login import login_user, logout_user, login_required
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
|
||||
from app import db
|
||||
from app.auth import auth
|
||||
from app.email import send_email
|
||||
from app.models import User
|
||||
from app.auth.forms import LoginForm, RegistrationForm
|
||||
|
||||
|
||||
|
||||
@auth.before_app_request
|
||||
def before_request():
|
||||
if current_user.is_authenticated and not current_user.confirmed and request.blueprint != 'auth' and request.endpoint != 'static':
|
||||
return redirect(url_for('auth.unconfirmed'))
|
||||
|
||||
|
||||
@auth.route('/unconfirmed')
|
||||
def unconfirmed():
|
||||
if current_user.is_anonymous or current_user.confirmed:
|
||||
return redirect(url_for('main.index'))
|
||||
return render_template('auth/unconfirmed.html')
|
||||
|
||||
@auth.route('/login', methods=['get', 'post'])
|
||||
def login():
|
||||
form = LoginForm()
|
||||
@@ -43,8 +56,46 @@ def register():
|
||||
if form.validate_on_submit():
|
||||
user = User(email=form.email.data, username=form.username.data, password=form.password.data)
|
||||
db.session.add(user)
|
||||
|
||||
db.session.commit()
|
||||
flash('You can now login', category='success')
|
||||
|
||||
token = user.generate_confirmation_token()
|
||||
|
||||
send_email(user.email, 'Confirm Your Yo!nk Account', 'auth/email/confirm', user=user, token=token)
|
||||
|
||||
flash(f'A confirmation email was sent to {user.email}', category='success')
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
return render_template('auth/register.html', form=form)
|
||||
return render_template('auth/register.html', form=form)
|
||||
|
||||
|
||||
@auth.route('/confirm/<token>')
|
||||
@login_required
|
||||
def confirm(token):
|
||||
if current_user.confirmed:
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
if current_user.confirm(token):
|
||||
db.session.commit()
|
||||
flash('Your account has been confirmed. Thank you!')
|
||||
else:
|
||||
flash('Invalid or expired confirmation link')
|
||||
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
|
||||
@auth.route('/confirm')
|
||||
@login_required
|
||||
def resend_confirm():
|
||||
token = current_user.generate_confirmation_token()
|
||||
|
||||
send_email(current_user.email, 'Confirm Your Yo!nk Account', 'auth/email/confirm', user=current_user, token=token)
|
||||
|
||||
flash(f'A new confirmation email was sent to {current_user.email}', category='success')
|
||||
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
|
||||
# TODO: password updates
|
||||
# TODO: password reset
|
||||
# TODO: email updates
|
||||
Reference in New Issue
Block a user