From 79f511c83794d65d06bcd531c5c0074f52bce7b4 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Sat, 8 Jun 2024 19:18:15 -0400 Subject: [PATCH] frontend: add username login --- core/data/schema/card.py | 2 +- core/data/schema/user.py | 4 ++++ core/frontend.py | 8 ++++++-- core/templates/gate/gate.jinja | 12 ++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/core/data/schema/card.py b/core/data/schema/card.py index c31e1b2..cd5c647 100644 --- a/core/data/schema/card.py +++ b/core/data/schema/card.py @@ -121,7 +121,7 @@ class CardData(BaseData): 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 diff --git a/core/data/schema/user.py b/core/data/schema/user.py index 5f1ccf2..8c3695c 100644 --- a/core/data/schema/user.py +++ b/core/data/schema/user.py @@ -120,3 +120,7 @@ class UserData(BaseData): result = await self.execute(sql) return result is not None + + async def get_user_by_username(self, username: str) -> Optional[Row]: + result = await self.execute(aime_user.select(aime_user.c.username == username)) + if result: return result.fetchone() diff --git a/core/frontend.py b/core/frontend.py index bb3e9aa..b9d1604 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -308,8 +308,12 @@ class FE_Gate(FE_Base): uid = await self.data.card.get_user_id_from_card(access_code) if uid is None: - self.logger.debug(f"Failed to find user for card {access_code}") - return RedirectResponse("/gate/?e=1", 303) + user = await self.data.user.get_user_by_username(access_code) # Lookup as username + if not user: + self.logger.debug(f"Failed to find user for card/username {access_code}") + return RedirectResponse("/gate/?e=1", 303) + + uid = user['id'] user = await self.data.user.get_user(uid) if user is None: diff --git a/core/templates/gate/gate.jinja b/core/templates/gate/gate.jinja index ca3e2eb..d398cbd 100644 --- a/core/templates/gate/gate.jinja +++ b/core/templates/gate/gate.jinja @@ -15,18 +15,18 @@ -moz-appearance: textfield; } -
+
-
- +
+ +
20 Digit access code from a card registered to your account, or your account username. (NOT your username from a game!)

- + +
Leave blank if registering for the webui. Your card must have been used on a game connected to this server to register.

-
*To register for the webui, type in the access code of your card, as shown in a game, and leave the password field blank.
-
*If you have not registered a card with this server, you cannot create a webui account.
{% endblock content %} \ No newline at end of file