-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authorizers.py
61 lines (46 loc) · 1.45 KB
/
Authorizers.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
from flask_app.main.Authorizer.BaseAuthorizers import BaseAuthorizer
from flask_app.main.constants import (
AUTH_SMS,
AUTH_EMAIL,
AUTH_ROBOT
)
class Authorizer_SMS(BaseAuthorizer):
def __init__(self):
self.TEMPLATE_NAME = AUTH_SMS
self.authorized = False
def verify_code(self, code):
print(f"Verifying SMS code {code}")
self.authorized = True
def verify(self, code):
print(f"Verifying SMS code {code}")
self.verify_code(code)
def is_authorized(self) -> bool:
return self.authorized
class Authorizer_Email(BaseAuthorizer):
def __init__(self):
self.TEMPLATE_NAME = AUTH_EMAIL
self.authorized = False
def verify_code(self, code):
print(f"Verifying Emailauth code {code}")
self.authorized = True
def verify(self, code):
print(f"Verifying Email auth code {code}")
self.verify_code(code)
def is_authorized(self) -> bool:
return self.authorized
class Authorizer_Robot(BaseAuthorizer):
def __init__(self):
self.TEMPLATE_NAME = AUTH_ROBOT
self.authorized = False
def not_a_robot(self):
self.authorized = True
def verify(self, code):
print(f"Verifying robot")
self.not_a_robot()
def is_authorized(self) -> bool:
return self.authorized
AUTH_MAPPING = {
AUTH_SMS: Authorizer_SMS(),
AUTH_EMAIL: Authorizer_Email(),
AUTH_ROBOT: Authorizer_Robot()
}