From 4149944d5634c2cb32ab862e64cd07225990530c Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Mon, 12 Feb 2024 15:53:28 -0500 Subject: [PATCH] aimedb: update card last login time properly --- core/aimedb.py | 7 ++++++- core/data/schema/card.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/aimedb.py b/core/aimedb.py index c53ffcb..3b62ba5 100644 --- a/core/aimedb.py +++ b/core/aimedb.py @@ -191,6 +191,8 @@ class AimedbServlette(): self.logger.info( f"access_code {req.access_code} -> user_id {ret.user_id}" ) + + await self.data.card.update_card_last_login(req.access_code) return ret async def handle_lookup_ex(self, data: bytes, resp_code: int) -> ADBBaseResponse: @@ -220,6 +222,7 @@ class AimedbServlette(): self.logger.debug(f"Generated auth token {auth_key}") ret.auth_key = auth_key_full + await self.data.card.update_card_last_login(req.access_code) return ret async def handle_felica_lookup(self, data: bytes, resp_code: int) -> bytes: @@ -291,7 +294,9 @@ class AimedbServlette(): auth_key_full = auth_key.encode() + (b"\0" * auth_key_extra_len) self.logger.debug(f"Generated auth token {auth_key}") resp.auth_key = auth_key_full - + + + await self.data.card.update_card_last_login(access_code) return resp async def handle_campaign_clear(self, data: bytes, resp_code: int) -> ADBBaseResponse: diff --git a/core/data/schema/card.py b/core/data/schema/card.py index 011efe1..c31e1b2 100644 --- a/core/data/schema/card.py +++ b/core/data/schema/card.py @@ -74,6 +74,7 @@ class CardData(BaseData): if card["is_banned"]: return True return False + async def get_card_locked(self, access_code: str) -> Optional[bool]: """ Given a 20 digit access code as a string, check if the card is locked @@ -112,6 +113,15 @@ class CardData(BaseData): return None return result.lastrowid + async def update_card_last_login(self, access_code: str) -> None: + sql = aime_card.update(aime_card.c.access_code == access_code).values( + last_login_date=func.now() + ) + + result = await self.execute(sql) + if result is None: + self.logger.warn(f"Failed to update last login time for {access_code}") + def to_access_code(self, luid: str) -> str: """ Given a felica cards internal 16 hex character luid, convert it to a 0-padded 20 digit access code as a string