diff --git a/account/views.py b/account/views.py index cb2ee56..5b71b86 100644 --- a/account/views.py +++ b/account/views.py @@ -295,18 +295,28 @@ class UserLogin(viewsets.ViewSet): try: if user is not None: login(request, user) - if user_type == USER_TYPE_FLAG["FIRST"]: + if user_type == USER_TYPE_FLAG["TWO"]: guardian_data = Guardian.objects.filter(user__username=username, is_verified=True).last() if guardian_data: serializer = GuardianSerializer( guardian_data, context={'user_type': user_type} ).data - elif user_type == USER_TYPE_FLAG["TWO"]: + else: + return custom_error_response( + ERROR_CODE["2070"], + response_status=status.HTTP_401_UNAUTHORIZED + ) + elif user_type == USER_TYPE_FLAG["FIRST"]: junior_data = Junior.objects.filter(auth__username=username, is_verified=True).last() if junior_data: serializer = JuniorSerializer( junior_data, context={'user_type': user_type} ).data + else: + return custom_error_response( + ERROR_CODE["2071"], + response_status=status.HTTP_401_UNAUTHORIZED + ) else: return custom_error_response( ERROR_CODE["2069"], diff --git a/base/messages.py b/base/messages.py index c7863c8..10fbfaa 100644 --- a/base/messages.py +++ b/base/messages.py @@ -95,7 +95,9 @@ ERROR_CODE = { "2066": "Task does not exist or not in expired state", "2067": "Action not allowed. User type missing.", "2068": "No guardian associated with this junior", - "2069": "Invalid user type" + "2069": "Invalid user type", + "2070": "You did not find as a guardian", + "2071": "You did not find as a junior" } """Success message code"""