From 37e14805f6b3bb7e0a303610ecd438051561d2ee Mon Sep 17 00:00:00 2001 From: Itamar Shefi Date: Sun, 11 Aug 2024 10:47:03 +0300 Subject: [PATCH] supply subscription info --- app.py | 1 + routers/user_routes.py | 4 +++- templates/index.html | 8 ++++++++ templates/menu.html | 1 - 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 400c705..b0a9f17 100644 --- a/app.py +++ b/app.py @@ -126,6 +126,7 @@ async def get_user( if expiry := user_logic.get_subscription_expiry(request.state.user): is_active = expiry > datetime.utcnow() request.state.has_active_subscription = is_active + request.state.expires_at = str(expiry.date()) else: request.state.user = None return await call_next(request) diff --git a/routers/user_routes.py b/routers/user_routes.py index e4c104d..4b5b9ca 100644 --- a/routers/user_routes.py +++ b/routers/user_routes.py @@ -10,6 +10,7 @@ from fastapi.requests import Request from common import config +from logic.user_logic import UserLogic user_router = APIRouter(prefix="/api/user") @@ -20,6 +21,7 @@ async def get_user_info(request: Request) -> dict[str, str | datetime.datetime | if not user: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) else: + user_logic = UserLogic(request.app.state.session) hasher = hashlib.sha3_256() # TODO: make this consistent hasher.update(user.email.encode() + config.secret_key.encode()) @@ -28,5 +30,5 @@ async def get_user_info(request: Request) -> dict[str, str | datetime.datetime | "email": user.email, "picture": user.picture, "name": f"{user.given_name} {user.family_name}", - "subscription_expiry": user.subscription_expiry, + "subscription_expiry": user_logic.get_subscription_expiry(user), } diff --git a/templates/index.html b/templates/index.html index 63b9087..7fc7090 100644 --- a/templates/index.html +++ b/templates/index.html @@ -50,6 +50,7 @@

{{notification["heading"]}}

+

{{quote[0]}}

@@ -109,6 +110,13 @@

{{notification["heading"]}}

+
+ {% if request.state.has_active_subscription %} + + תודה על התרומה! רמזים חופשי עד {{ request.state.expires_at }} + + {% endif %} +

diff --git a/templates/menu.html b/templates/menu.html index 6e4cfe0..2560b7d 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -120,5 +120,4 @@

נחשו את המילה הסודית

-