-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorators.py
More file actions
61 lines (45 loc) · 1.53 KB
/
Copy pathdecorators.py
File metadata and controls
61 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import request, abort
import jwt
from constants import JWT_ALGORITHM, JWT_SECRET_KEY
from implemented import user_service
def auth_required(func):
def wrapper(*args, **kwargs):
if "Authorization" not in request.headers:
print('Вы не вошли в аккаунт')
abort(401, "Вы не вошли в аккаунт")
data = request.headers["Authorization"]
token = data.split("Bearer ")[-1]
try:
jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
except Exception as e:
print(f"jwt decode error {e}")
abort(401)
return func(*args, **kwargs)
return wrapper
def admin_required(func):
def wrapper(*args, **kwargs):
if request.headers["Role"] == '1':
print('Succeed')
else:
print('Your are not admin')
abort(403, "You are not admin")
return func(*args, **kwargs)
return wrapper
def restaraunt_required(func):
def wrapper(*args, **kwargs):
if request.headers["Role"] == '2':
print('Succeed')
else:
print('Your are not User')
abort(403, "You are not User")
return func(*args, **kwargs)
return wrapper
def user_required(func):
def wrapper(*args, **kwargs):
if request.headers["Role"] == '3':
print('Succeed')
else:
print('Your are not shef')
abort(403, "You are not shef")
return func(*args, **kwargs)
return wrapper