21 lines
840 B
Python
21 lines
840 B
Python
|
from functools import wraps
|
||
|
def login_required(**kwargs):
|
||
|
import geruecht.controller.accesTokenController as ac
|
||
|
from geruecht.model import BAR, USER, MONEY, GASTRO
|
||
|
from flask import request, jsonify
|
||
|
accessController = ac.AccesTokenController()
|
||
|
groups = [USER, BAR, GASTRO, MONEY]
|
||
|
if "groups" in kwargs:
|
||
|
groups = kwargs["groups"]
|
||
|
def real_decorator(func):
|
||
|
@wraps(func)
|
||
|
def wrapper(*args, **kwargs):
|
||
|
token = request.headers.get('Token')
|
||
|
accToken = accessController.validateAccessToken(token, groups)
|
||
|
kwargs['accToken'] = accToken
|
||
|
if accToken:
|
||
|
return func(*args, **kwargs)
|
||
|
else:
|
||
|
return jsonify({"error": "error", "message": "permission denied"}), 401
|
||
|
return wrapper
|
||
|
return real_decorator
|