diff options
Diffstat (limited to 'mu4web/user/__init__.py')
-rw-r--r-- | mu4web/user/__init__.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mu4web/user/__init__.py b/mu4web/user/__init__.py index bb14f67..c0dbda9 100644 --- a/mu4web/user/__init__.py +++ b/mu4web/user/__init__.py @@ -1,19 +1,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() |