Skip to content

Commit

Permalink
feat: Allow login with email (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBursch authored Nov 12, 2024
1 parent 2762b71 commit 94b99bf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions backend/app/controller/auth/auth_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
from app.errors import NotFoundRequest, UnauthorizedRequest
from app.service import mail
from .schemas import Login, Signup, CreateLongLivedToken, GetOIDCLoginUrl, LoginOIDC
from app.config import EMAIL_MANDATORY, FRONT_URL, jwt, OPEN_REGISTRATION, DISABLE_USERNAME_PASSWORD_LOGIN, oidc_clients
from app.config import (
EMAIL_MANDATORY,
FRONT_URL,
jwt,
OPEN_REGISTRATION,
DISABLE_USERNAME_PASSWORD_LOGIN,
oidc_clients,
)

auth = Blueprint("auth", __name__)

Expand Down Expand Up @@ -52,7 +59,12 @@ def user_lookup_callback(_jwt_header, jwt_data) -> User:
@validate_args(Login)
def login(args):
username = args["username"].lower().replace(" ", "")
user = User.find_by_username(username)
user = None
if "@" not in username:
user = User.find_by_username(username)
else:
user = User.find_by_email(username)

if not user or not user.check_password(args["password"]):
raise UnauthorizedRequest(
message="Unauthorized: IP {} login attemp with wrong username or password".format(
Expand Down Expand Up @@ -83,7 +95,7 @@ def login(args):
@auth.route("signup", methods=["POST"])
@validate_args(Signup)
def signup(args):
username = args["username"].lower().replace(" ", "")
username = args["username"].lower().replace(" ", "").replace("@", "")
user = User.find_by_username(username)
if user:
return "Request invalid: username", 400
Expand Down

0 comments on commit 94b99bf

Please sign in to comment.