feat(user): support login with any case of username & email

This commit is contained in:
MingxuanGame
2025-08-26 11:39:55 +00:00
parent 8d9f1d2750
commit f8535fdce4
4 changed files with 66 additions and 10 deletions

View File

@@ -111,13 +111,15 @@ async def authenticate_user_legacy(db: AsyncSession, name: str, password: str) -
pw_md5 = hashlib.md5(password.encode()).hexdigest()
# 2. 根据用户名查找用户
statement = select(User).where(User.username == name).options()
user = (await db.exec(statement)).first()
if not user:
user = None
user = (await db.exec(select(User).where(User.username == name))).first()
if user is None:
user = (await db.exec(select(User).where(User.email == name))).first()
if user is None and name.isdigit():
user = (await db.exec(select(User).where(User.id == int(name)))).first()
if user is None:
return None
await db.refresh(user)
# 3. 验证密码
if user.pw_bcrypt is None or user.pw_bcrypt == "":
return None