summaryrefslogtreecommitdiff
path: root/src/frest/decorators.py
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-04-06 21:54:53 +0200
committerSanto Cariotti <dcariotti24@gmail.com>2020-04-06 21:54:53 +0200
commit3a2246e26e9febe3c15e2ddc1e7e6f320f86fe15 (patch)
tree9cbd95771d38dfd66bedb4a447470391d34a68eb /src/frest/decorators.py
parent6188a952974b3e268936beb1027ea58fbfaa67aa (diff)
chore: move package in frest folder
Diffstat (limited to 'src/frest/decorators.py')
-rw-r--r--src/frest/decorators.py40
1 files changed, 0 insertions, 40 deletions
diff --git a/src/frest/decorators.py b/src/frest/decorators.py
deleted file mode 100644
index 7ce79d7..0000000
--- a/src/frest/decorators.py
+++ /dev/null
@@ -1,40 +0,0 @@
-from flask import request, abort
-from auth.models import Token
-from functools import wraps
-
-
-def check_token(f):
- @wraps(f)
- def inner(*args, **kwargs):
- userid = request.url.split("/")[-1]
- headers = request.headers
- if not headers.get("Authorization"):
- abort(403)
-
- auth = request.headers.get("Authorization")
- token = Token.query.filter_by(string=auth).first()
- if not token:
- abort(403)
-
- if userid.isdigit():
- if int(userid) != token.user.userId and not token.user.is_admin:
- abort(403)
-
- return f(*args, **kwargs)
-
- return inner
-
-
-def admin_required(f):
- @wraps(f)
- def inner(*args, **kwargs):
- header = request.headers
-
- auth = request.headers.get("Authorization")
- token = Token.query.filter_by(string=auth).first()
- if not token.user.is_admin:
- abort(403)
-
- return f(*args, **kwargs)
-
- return inner