2017-02-10 06:10:44 +01:00
|
|
|
from functools import wraps
|
2017-03-25 08:52:56 +01:00
|
|
|
from flask import url_for, redirect, session, jsonify, abort
|
2017-02-10 06:10:44 +01:00
|
|
|
|
|
|
|
def valid_session_required(api=False):
|
|
|
|
def decorator(f):
|
|
|
|
@wraps(f)
|
|
|
|
def decorated_function(*args, **kwargs):
|
|
|
|
if 'unauthenticated' not in session or 'user_id' not in session or 'username' not in session:
|
|
|
|
if api:
|
|
|
|
return jsonify(error=True, message="Unauthenticated session"), 403
|
2017-03-25 08:52:56 +01:00
|
|
|
redirect(url_for('user.logout'))
|
2017-02-10 06:10:44 +01:00
|
|
|
if session['unauthenticated'] and 'user_keys' not in session:
|
|
|
|
session['user_keys'] = {}
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return decorated_function
|
|
|
|
return decorator
|
2017-03-25 08:52:56 +01:00
|
|
|
|
|
|
|
def discord_users_only(api=False):
|
|
|
|
def decorator(f):
|
|
|
|
@wraps(f)
|
|
|
|
def decorated_function(*args, **kwargs):
|
|
|
|
if 'unauthenticated' not in session or session['unauthenticated']:
|
|
|
|
if api:
|
|
|
|
return jsonify(error=True, message="Not logged in as a discord user"), 403
|
|
|
|
return redirect(url_for("user.login_authenticated"))
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return decorated_function
|
|
|
|
return decorator
|