src/auth/models.py : classe User Flask-Login (#73)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Colin Maudry
2026-04-20 17:25:56 +02:00
parent 92fe76d072
commit 72fd495c5b
2 changed files with 63 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import sqlite3
from src.auth import db
class User:
def __init__(self, row: sqlite3.Row):
self.id: int = row["id"]
self.email: str = row["email"]
self.email_verified: bool = bool(row["email_verified"])
@property
def is_authenticated(self) -> bool:
return True
@property
def is_active(self) -> bool:
return True
@property
def is_anonymous(self) -> bool:
return False
def get_id(self) -> str:
return str(self.id)
def load_user(user_id: str) -> User | None:
try:
uid = int(user_id)
except (TypeError, ValueError):
return None
row = db.get_user_by_id(uid)
return User(row) if row else None