diff options
author | Frederick Muriuki Muriithi | 2023-01-28 03:16:45 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-01-28 03:20:01 +0300 |
commit | 76c464946d01073b8bcb757345d0d42b9a8207e4 (patch) | |
tree | 7d5cd20018c65207b809842277e7533d7490de7b /gn3/auth/authentication | |
parent | e6e173b74d381f590ff5a8e7957489ea4d50c06b (diff) | |
download | genenetwork3-76c464946d01073b8bcb757345d0d42b9a8207e4.tar.gz |
auth: rework dictify
Define a Protocol type to use with the `dictify` function and implement the
`dictify` methods for the various classes.
Diffstat (limited to 'gn3/auth/authentication')
-rw-r--r-- | gn3/auth/authentication/users.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gn3/auth/authentication/users.py b/gn3/auth/authentication/users.py index ee3b5c2..b2d8d53 100644 --- a/gn3/auth/authentication/users.py +++ b/gn3/auth/authentication/users.py @@ -1,6 +1,6 @@ """User-specific code and data structures.""" from uuid import UUID, uuid4 -from typing import Tuple, NamedTuple +from typing import Any, Tuple, NamedTuple import bcrypt from pymonad.maybe import Just, Maybe, Nothing @@ -17,6 +17,10 @@ class User(NamedTuple): """Return the user's UUID. Mostly for use with Authlib.""" return self.user_id + def dictify(self) -> dict[str, Any]: + """Return a dict representation of `User` objects.""" + return {"user_id": self.user_id, "email": self.email, "name": self.name} + def user_by_email(conn: db.DbConnection, email: str) -> Maybe: """Retrieve user from database by their email address""" with db.cursor(conn) as cursor: |