haldis/app/login.py
mcbloch d0863325a5
Restructuring the codebase!
But for real, it's a real shitstorm in there.
- Added context by making the init go through a function
  and not implicitly happen via imports
- Fixup all context and contextless function mixups
- splitup the models in sensible different files
- give the dump of view functions in views/__init__.py their own file
- add all routes via blueprints, not half of them
- move the slack notifications function and class to its own file,
    no idea what it was doing in a views file in the first place.
2019-08-28 03:46:04 +02:00

33 lines
721 B
Python

from flask import abort, Blueprint
from flask import redirect, session, url_for
from flask_login import current_user, logout_user
from models import User
from zeus import zeus_login
auth_bp = Blueprint('auth_bp', __name__)
def init_login(app):
@app.login_manager.user_loader
def load_user(userid):
return User.query.filter_by(id=userid).first()
@auth_bp.route('/login')
def login():
return zeus_login()
@auth_bp.route('/logout')
def logout():
if 'zeus_token' in session:
session.pop('zeus_token', None)
logout_user()
return redirect(url_for('general_bp.home'))
def before_request():
if current_user.is_anonymous() or not current_user.is_allowed():
abort(401)