From 2a0bb98bd338bfc55f56e4a1ded6f5e3d1c73ee8 Mon Sep 17 00:00:00 2001 From: bobbyvish Date: Mon, 11 Mar 2024 15:34:47 +0530 Subject: [PATCH] Updated error msg in login --- module_auth/api/utils.py | 2 +- module_auth/api/views.py | 12 ++++++++---- module_project/constants.py | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/module_auth/api/utils.py b/module_auth/api/utils.py index 3e7be9b..4818bce 100644 --- a/module_auth/api/utils.py +++ b/module_auth/api/utils.py @@ -175,7 +175,7 @@ def authticate_with_otp_and_passsword(principal: IAmPrincipal, otp=None, passwor print(password) if not principal.check_password(password): return ApiResponse.error( - message=constants.INVALID_PASSWORD, errors=constants.INVALID_PASSWORD + message=constants.INCORRECT_CREDENTIALS, errors=constants.INCORRECT_CREDENTIALS ) print("after passsowrd", password) diff --git a/module_auth/api/views.py b/module_auth/api/views.py index 5a1509b..7a5a7e2 100644 --- a/module_auth/api/views.py +++ b/module_auth/api/views.py @@ -81,10 +81,14 @@ class LoginView(APIView): password = request.data.get("password") player_id = request.data.get("player_id") - principal = get_principal_by_email(email=email) - - if isinstance(principal, Response): - return principal + try: + principal = IAmPrincipal.objects.get(email=email) + except IAmPrincipal.DoesNotExist: + error_response = { + "message": constants.INCORRECT_CREDENTIALS, + "errors": constants.INCORRECT_CREDENTIALS, + } + return ApiResponse.error(**error_response) validation_result = authticate_with_otp_and_passsword( principal, otp=otp, password=password diff --git a/module_project/constants.py b/module_project/constants.py index 99ac25a..0616887 100644 --- a/module_project/constants.py +++ b/module_project/constants.py @@ -34,6 +34,7 @@ SESSION_EXPIRED = "Your session has expired. Please log in again." ACCOUNT_DEACTIVATED = "Your account is inactive. Please contact support." EMAIL_EXISTS = "This email address is already in use. Please use a different email." INVALID_EMAIL_PASSWORD = "Invalid email or password." +INCORRECT_CREDENTIALS = "Invalid Credentials" INVALID_PASSWORD = "Invalid password." PASSWORD_NOT_MATCH = "Password do not match" INVALID_OPERATION = "Invalid operation requested."