16 lines
494 B
Python
16 lines
494 B
Python
from typing import Optional
|
|
from app.db import get_db
|
|
from flask_login import UserMixin
|
|
|
|
class User(UserMixin):
|
|
def __init__(self, id: int, username: str ):
|
|
self.id: int = id
|
|
self.username: str = username
|
|
|
|
@staticmethod
|
|
def get(user_id: int | str) -> Optional["User"]:
|
|
db = get_db()
|
|
user = db.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
|
if user:
|
|
return User(user["id"], user["username"])
|
|
return None |