-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
92 lines (66 loc) · 1.94 KB
/
models.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from flask import current_app, redirect, url_for
from modules.Auth.user_db import UserDatabase
from functools import wraps
from flask_login import current_user, AnonymousUserMixin
ACCESS = {
'Guest': 3,
'user': 2,
'admin': 1
}
def requires_access_level(access_level):
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if not current_user.allowed(access_level):
return redirect(url_for("dashboard.dashboard_view"))
return f(*args, **kwargs)
return decorated_function
return decorator
class User():
def __init__(self, user_id):
self.user_id = user_id
db = UserDatabase(current_app.config["USERS_DB"])
user_data = db.check_user(self.user_id)
self.id = user_data[2]
self.username = user_data[0]
self.access = user_data[3]
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return self.user_id
def is_admin(self):
return self.access == ACCESS['admin']
def allowed(self, access_level):
if self.access ==access_level[0]:
return True
else:
return False
def __unicode__(self):
return self.user_id
class Anonymous(AnonymousUserMixin):
'''
This is the default object for representing an anonymous user.
'''
@property
def is_authenticated(self):
return False
@property
def is_active(self):
return False
@property
def is_anonymous(self):
return True
def get_id(self):
return
def __init__(self):
self.username = "Guest"
self.access= 3
def allowed(self, access_level):
if self.access == access_level[0]:
return True
else:
return False