haldis/app/login.py

33 lines
721 B
Python
Raw Normal View History

from flask import abort, Blueprint
from flask import redirect, session, url_for
from flask_login import current_user, logout_user
2015-03-31 20:15:22 +02:00
from models import User
from zeus import zeus_login
2019-09-05 03:33:29 +02:00
auth_bp = Blueprint("auth_bp", __name__)
2015-03-31 20:15:22 +02:00
def init_login(app):
@app.login_manager.user_loader
def load_user(userid):
return User.query.filter_by(id=userid).first()
2015-03-31 20:15:22 +02:00
2019-09-05 03:33:29 +02:00
@auth_bp.route("/login")
2015-03-31 20:15:22 +02:00
def login():
return zeus_login()
2019-09-05 03:33:29 +02:00
@auth_bp.route("/logout")
2015-03-31 20:15:22 +02:00
def logout():
2019-09-05 03:33:29 +02:00
if "zeus_token" in session:
session.pop("zeus_token", None)
2015-03-31 20:15:22 +02:00
logout_user()
2019-09-05 03:33:29 +02:00
return redirect(url_for("general_bp.home"))
2015-03-31 20:15:22 +02:00
def before_request():
if current_user.is_anonymous() or not current_user.is_allowed():
abort(401)