aimedb: update card last login time properly

This commit is contained in:
Hay1tsme 2024-02-12 15:53:28 -05:00
parent d4e00781c8
commit 4149944d56
2 changed files with 16 additions and 1 deletions

View File

@ -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:
@ -292,6 +295,8 @@ class AimedbServlette():
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:

View File

@ -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