jira-25 access token API

This commit is contained in:
jain
2023-07-14 15:02:53 +05:30
parent 7b9b5a2c6f
commit d163f43c85
4 changed files with 44 additions and 14 deletions

View File

@ -37,6 +37,7 @@ from rest_framework import status
import requests
from rest_framework.response import Response
from django.conf import settings
from rest_framework_simplejwt.tokens import RefreshToken
from junior.serializers import JuniorProfileSerializer
from guardian.serializers import GuardianProfileSerializer
@ -302,7 +303,8 @@ class UserLogin(viewsets.ViewSet):
email_verified = UserEmailOtp.objects.filter(email=username).last()
refresh = RefreshToken.for_user(user)
access_token = str(refresh.access_token)
data = {"auth_token":access_token, "is_profile_complete": False,
refresh_token = str(refresh)
data = {"auth_token":access_token, "refresh_token":refresh_token, "is_profile_complete": False,
"user_type": email_verified.user_type,
}
is_verified = False
@ -336,7 +338,8 @@ class UserLogin(viewsets.ViewSet):
logging.error(e)
refresh = RefreshToken.for_user(user)
access_token = str(refresh.access_token)
data = {"auth_token": access_token, "user_role": '3'}
refresh_token = str(refresh)
data = {"auth_token": access_token, "refresh_token":refresh_token, "user_type": '3'}
return custom_response(None, data, response_status=status.HTTP_200_OK)
class UserEmailVerification(viewsets.ModelViewSet):
@ -373,7 +376,8 @@ class UserEmailVerification(viewsets.ModelViewSet):
guardian_data.save()
refresh = RefreshToken.for_user(user_obj)
access_token = str(refresh.access_token)
return custom_response(SUCCESS_CODE['3011'], {"auth_token":access_token},
refresh_token = str(refresh)
return custom_response(SUCCESS_CODE['3011'], {"auth_token":access_token, "refresh_token":refresh_token},
response_status=status.HTTP_200_OK)
else:
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
@ -521,3 +525,17 @@ class LogoutAPIView(views.APIView):
logout(request)
request.session.flush()
return custom_response(SUCCESS_CODE['3020'], response_status=status.HTTP_200_OK)
class AccessTokenAPIView(views.APIView):
"""generate access token API"""
def post(self, request):
# Assuming you have a refresh_token string
refresh_token = request.data['refresh_token']
# Create a RefreshToken instance from the refresh token string
refresh = RefreshToken(refresh_token)
# Generate a new access token
access_token = str(refresh.access_token)
data = {"auth_token": access_token}
return custom_response(None, data, response_status=status.HTTP_200_OK)