endorsement/login.py
2018-11-29 16:14:20 +01:00

30 lines
641 B
Python

from flask import redirect, session, url_for
from flask_login import LoginManager, logout_user
from app import app
from models import User
from zeus import zeus_login
login_manager = LoginManager()
login_manager.init_app(app)
@login_manager.user_loader
def load_user(userid):
return User.query.filter_by(id=userid).first()
@app.errorhandler(401)
def custom_401(_):
return redirect(url_for('login'))
@app.route('/login')
def login():
return zeus_login()
@app.route('/logout')
def logout():
if 'zeus_token' in session:
session.pop('zeus_token', None)
logout_user()
return redirect(url_for('all_users'))