Last active
January 22, 2020 19:11
-
-
Save Porter97/06b44bc5732a4847ce14d17b97def8e6 to your computer and use it in GitHub Desktop.
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 request, redirect, render_template, url_for, flash | |
from flask_login import login_user, logout_user, login_required, current_user | |
from .forms import LoginForm, RegistrationForm | |
@auth.before_app_request | |
def before_request(): | |
if current_user.is_authenticated: | |
current_user.ping() | |
if not current_user.confirmed \ | |
and request.endpoint \ | |
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() | |
if form.validate_on_submit(): | |
user = User.query.filter_by(email=form.email.data.lower()) | |
if user is not None and user.verify_password(form.password.data): | |
login_user(user, form.remember_me.data) | |
next = request.args.get('next') | |
if next is None or not next.startswith('/'): | |
next = url_for('main.index') | |
return redirect(next) | |
flash('Invalid email or password.') | |
return render_template('auth/login.html', form=form) | |
@auth.route(‘/logout’) | |
@login_required | |
def logout(): | |
logout_user() | |
flash(‘You have been logged out.’) | |
return redirect(url_for(‘main.index’) | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment