diff options
Diffstat (limited to 'gn3/auth/authentication/users.py')
-rw-r--r-- | gn3/auth/authentication/users.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gn3/auth/authentication/users.py b/gn3/auth/authentication/users.py index 4854d18..4adee61 100644 --- a/gn3/auth/authentication/users.py +++ b/gn3/auth/authentication/users.py @@ -2,8 +2,22 @@ from uuid import UUID from typing import NamedTuple +from pymonad.maybe import Just, Maybe, Nothing + +from gn3.auth import db + class User(NamedTuple): """Class representing a user.""" user_id: UUID email: str name: str + +def user_by_email(conn: db.DbConnection, email: str) -> Maybe: + with db.cursor(conn) as cursor: + cursor.execute("SELECT * FROM users WHERE email=?", (email,)) + row = cursor.fetchone() + + if row: + return Just(User(UUID(row["user_id"]), row["email"], row["name"])) + + return Nothing |