mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
login api with user type
This commit is contained in:
@ -295,18 +295,28 @@ class UserLogin(viewsets.ViewSet):
|
|||||||
try:
|
try:
|
||||||
if user is not None:
|
if user is not None:
|
||||||
login(request, user)
|
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()
|
guardian_data = Guardian.objects.filter(user__username=username, is_verified=True).last()
|
||||||
if guardian_data:
|
if guardian_data:
|
||||||
serializer = GuardianSerializer(
|
serializer = GuardianSerializer(
|
||||||
guardian_data, context={'user_type': user_type}
|
guardian_data, context={'user_type': user_type}
|
||||||
).data
|
).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()
|
junior_data = Junior.objects.filter(auth__username=username, is_verified=True).last()
|
||||||
if junior_data:
|
if junior_data:
|
||||||
serializer = JuniorSerializer(
|
serializer = JuniorSerializer(
|
||||||
junior_data, context={'user_type': user_type}
|
junior_data, context={'user_type': user_type}
|
||||||
).data
|
).data
|
||||||
|
else:
|
||||||
|
return custom_error_response(
|
||||||
|
ERROR_CODE["2071"],
|
||||||
|
response_status=status.HTTP_401_UNAUTHORIZED
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(
|
return custom_error_response(
|
||||||
ERROR_CODE["2069"],
|
ERROR_CODE["2069"],
|
||||||
|
@ -95,7 +95,9 @@ ERROR_CODE = {
|
|||||||
"2066": "Task does not exist or not in expired state",
|
"2066": "Task does not exist or not in expired state",
|
||||||
"2067": "Action not allowed. User type missing.",
|
"2067": "Action not allowed. User type missing.",
|
||||||
"2068": "No guardian associated with this junior",
|
"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"""
|
"""Success message code"""
|
||||||
|
Reference in New Issue
Block a user