login api with user type

This commit is contained in:
jain
2023-08-14 15:16:16 +05:30
parent 11b9f00285
commit d3b0be953e
2 changed files with 15 additions and 3 deletions

View File

@ -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"],

View File

@ -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"""