frontend: add username login

This commit is contained in:
Hay1tsme 2024-06-08 19:18:15 -04:00
parent 8e6e5ea903
commit 79f511c837
4 changed files with 17 additions and 9 deletions

View File

@ -121,7 +121,7 @@ class CardData(BaseData):
result = await self.execute(sql) result = await self.execute(sql)
if result is None: if result is None:
self.logger.warn(f"Failed to update last login time for {access_code}") self.logger.warn(f"Failed to update last login time for {access_code}")
def to_access_code(self, luid: str) -> str: 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 Given a felica cards internal 16 hex character luid, convert it to a 0-padded 20 digit access code as a string

View File

@ -120,3 +120,7 @@ class UserData(BaseData):
result = await self.execute(sql) result = await self.execute(sql)
return result is not None 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()

View File

@ -308,8 +308,12 @@ class FE_Gate(FE_Base):
uid = await self.data.card.get_user_id_from_card(access_code) uid = await self.data.card.get_user_id_from_card(access_code)
if uid is None: if uid is None:
self.logger.debug(f"Failed to find user for card {access_code}") user = await self.data.user.get_user_by_username(access_code) # Lookup as username
return RedirectResponse("/gate/?e=1", 303) 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) user = await self.data.user.get_user(uid)
if user is None: if user is None:

View File

@ -15,18 +15,18 @@
-moz-appearance: textfield; -moz-appearance: textfield;
} }
</style> </style>
<form id="login" style="max-width: 240px; min-width: 10%;" action="/gate/gate.login" method="post"> <form id="login" style="max-width: 240px; min-width: 15%;" action="/gate/gate.login" method="post">
<div class="form-group row"> <div class="form-group row">
<label for="access_code">Card Access Code</label><br> <label for="access_code">Access Code or Username</label><br>
<input form="login" class="form-control" name="access_code" id="access_code" type="number" placeholder="00000000000000000000" maxlength="20" required> <input form="login" class="form-control" name="access_code" id="access_code" placeholder="00000000000000000000" maxlength="20" required aria-describedby="access_code_help">
<div id="access_code_help" class="form-text">20 Digit access code from a card registered to your account, or your account username. (NOT your username from a game!)</div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="passwd">Password</label><br> <label for="passwd">Password</label><br>
<input id="passwd" class="form-control" name="passwd" type="password" placeholder="password"> <input id="passwd" class="form-control" name="passwd" type="password" placeholder="password" aria-describedby="passwd_help">
<div id="passwd_help" class="form-text">Leave blank if registering for the webui. Your card must have been used on a game connected to this server to register.</div>
</div> </div>
<p></p> <p></p>
<input id="submit" class="btn btn-primary" style="display: block; margin: 0 auto;" form="login" type="submit" value="Login"> <input id="submit" class="btn btn-primary" style="display: block; margin: 0 auto;" form="login" type="submit" value="Login">
</form> </form>
<h6>*To register for the webui, type in the access code of your card, as shown in a game, and leave the password field blank.</h6>
<h6>*If you have not registered a card with this server, you cannot create a webui account.</h6>
{% endblock content %} {% endblock content %}