fix: allow users to login using their email

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-02-05 02:29:41 -08:00
parent f3360d1249
commit c80a16c254
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 18 additions and 1 deletions

View file

@ -2,6 +2,7 @@ from http import HTTPStatus
from fastapi import APIRouter, Form, HTTPException, Request
from fastapi.responses import HTMLResponse, RedirectResponse
from sqlalchemy import or_
import aurweb.config
@ -43,7 +44,9 @@ async def login_post(request: Request,
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST,
detail=_("Bad Referer header."))
user = db.query(User).filter(User.Username == user).first()
user = db.query(User).filter(
or_(User.Username == user, User.Email == user)
).first()
if not user:
return await login_template(request, next,
errors=["Bad username or password."])