haldis/app/login.py

34 lines
690 B
Python
Raw Normal View History

2015-03-31 20:15:22 +02:00
from flask import redirect, abort, session, url_for
2017-01-06 12:05:31 +01:00
from flask_login import LoginManager, current_user, logout_user
2015-03-31 20:15:22 +02:00
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.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('home'))
def before_request():
if current_user.is_anonymous() or not current_user.is_allowed():
abort(401)