2019-08-28 03:46:04 +02:00
|
|
|
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-08-28 03:46:04 +02:00
|
|
|
auth_bp = Blueprint('auth_bp', __name__)
|
2015-03-31 20:15:22 +02:00
|
|
|
|
|
|
|
|
2019-08-28 03:46:04 +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-08-28 03:46:04 +02:00
|
|
|
@auth_bp.route('/login')
|
2015-03-31 20:15:22 +02:00
|
|
|
def login():
|
|
|
|
return zeus_login()
|
|
|
|
|
|
|
|
|
2019-08-28 03:46:04 +02:00
|
|
|
@auth_bp.route('/logout')
|
2015-03-31 20:15:22 +02:00
|
|
|
def logout():
|
|
|
|
if 'zeus_token' in session:
|
|
|
|
session.pop('zeus_token', None)
|
|
|
|
logout_user()
|
2019-08-28 03:46:04 +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)
|