blob: c0dbda9b7cdf0d195ef48488048057bf75edf4ef (
plain)
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
|
"""
User authentication and sessions.
This is modeled to work well together with flash_login.
"""
class User:
"""
Default class for user session and authentication.
This implements flask-login's User Class protocol.
This abse implementation can construct any user, but no user can
by authenticated through it.
https://flask-login.readthedocs.io/en/latest/
"""
def __init__(self, username: str):
self._username = username
self._authenticated = False
# ---- User class protocoll ------------------------
def is_authenticated(self) -> bool:
"""
Return whetever a user is authenticated.
An authenticated user is someone who has provided valid
credentials (or similar)
"""
return self._authenticated
def is_active(self) -> bool:
"""
Return whetever a user is active.
An active user is someone who has an active account, suspended
or deactivated accounts aren't active.
"""
return True
def is_anonymous(self) -> bool:
"""Return true for anonymous users."""
return False
def get_id(self) -> str:
"""Get the unique identifier for this user."""
return self._username
# ---- Other stuff ---------------------------------
def validate(self, _: str) -> bool:
"""
Attempt to validate the users credentials.
The username comes from the constructed object.
:params password:
The attempted authentication token/password.
:returns:
True if the given token is correct, false otherwise.
"""
raise NotImplementedError()
|