Skip to content

Commit

Permalink
supply subscription info
Browse files Browse the repository at this point in the history
  • Loading branch information
ishefi committed Aug 11, 2024
1 parent d233345 commit 37e1480
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion routers/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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())
Expand All @@ -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),
}
8 changes: 8 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h3 id="notification-heading">{{notification["heading"]}}</h3>
</div>
</div>
</header>

<figure>
<blockquote class="review" cite="{{quote[3]}}">
<p class="review__quote">{{quote[0]}}</p>
Expand Down Expand Up @@ -109,6 +110,13 @@ <h3 id="notification-heading">{{notification["heading"]}}</h3>
<input type="submit" value="ניחוש" id="guess-btn">
</div>
</form>
<div>
{% if request.state.has_active_subscription %}
<i id="subscription-badge">
תודה על התרומה! רמזים חופשי עד {{ request.state.expires_at }}
</i>
{% endif %}
</div>
<input id="clue-btn" type="button" value="רמז">
<div id="response"></div>
<p><b id="timer" hidden></b></p>
Expand Down
1 change: 0 additions & 1 deletion templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,4 @@ <h3 id="rules-heading">נחשו את המילה הסודית</h3>
</div>
</div>
</div>

<div id="snackbar"></div>

0 comments on commit 37e1480

Please sign in to comment.