-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.py
42 lines (42 loc) · 1.65 KB
/
Utils.py
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
from flask import *
from functools import wraps
from API.Auther import *
def need_admin(func):
@wraps(func)
def decorated_function(*args, **kwargs):
print(request.cookies)
if 'device_token' not in request.cookies or 'device_id' not in request.cookies:
return redirect(url_for('api.login'))
a_h = AdminHelper(request.cookies['device_token'], request.cookies['device_id'])
if a_h.isValid():
role = a_h.getRole()
part_site = request.path.split('/')[1].lower()
if part_site is 'news':
if role in [1,2,3,4]:
return func(*args, **kwargs)
else:
return redirect(url_for('api.login'))
elif part_site is 'forms':
if role in [1,2,3,4]:
return func(*args, **kwargs)
else:
return redirect(url_for('api.login'))
elif part_site is 'users':
if role in [1,2,3]:
return func(*args, **kwargs)
else:
return redirect(url_for('api.login'))
elif part_site is 'pages':
if role in [1,2,3,4]:
return func(*args, **kwargs)
else:
return redirect(url_for('api.login'))
elif part_site is 'sidebar_menus':
if role in [1,2,3]:
return func(*args, **kwargs)
else:
return redirect(url_for('api.login'))
return func(*args, **kwargs)
else:
return redirect(url_for('login'))
return decorated_function