From 76c464946d01073b8bcb757345d0d42b9a8207e4 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Sat, 28 Jan 2023 03:16:45 +0300 Subject: auth: rework dictify Define a Protocol type to use with the `dictify` function and implement the `dictify` methods for the various classes. --- gn3/auth/authentication/users.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gn3/auth/authentication') 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: -- cgit v1.2.3