mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
jira-5 social login
This commit is contained in:
@ -167,7 +167,7 @@ class GuardianSerializer(serializers.ModelSerializer):
|
||||
"""Meta info"""
|
||||
model = Guardian
|
||||
fields = ['auth_token', 'refresh_token', 'email', 'first_name', 'last_name', 'country_code', 'phone', 'family_name', 'gender', 'dob',
|
||||
'referral_code', 'is_active', 'is_complete_profile', 'passcode',
|
||||
'referral_code', 'is_active', 'is_complete_profile', 'passcode', 'image',
|
||||
'created_at', 'updated_at', 'user_type']
|
||||
|
||||
|
||||
@ -201,7 +201,7 @@ class JuniorSerializer(serializers.ModelSerializer):
|
||||
"""Meta info"""
|
||||
model = Junior
|
||||
fields = ['auth_token', 'refresh_token', 'email', 'first_name', 'last_name', 'country_code', 'phone', 'gender', 'dob',
|
||||
'guardian_code', 'referral_code','is_active', 'is_complete_profile', 'created_at',
|
||||
'guardian_code', 'referral_code','is_active', 'is_complete_profile', 'created_at', 'image',
|
||||
'updated_at', 'user_type']
|
||||
|
||||
class EmailVerificationSerializer(serializers.ModelSerializer):
|
||||
|
@ -31,7 +31,6 @@ class GoogleLoginMixin:
|
||||
def google_login(self, request):
|
||||
access_token = request.data.get('access_token')
|
||||
user_type = request.data.get('user_type')
|
||||
# decoded_data = jwt.decode(access_token, options={"verify_signature": False})
|
||||
if not access_token:
|
||||
return Response({'error': 'Access token is required.'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -46,13 +45,11 @@ class GoogleLoginMixin:
|
||||
'refresh_token': None,
|
||||
}
|
||||
)
|
||||
print("credentials===>",credentials, '===>',credentials.token)
|
||||
user_info_endpoint = f'https://www.googleapis.com/oauth2/v3/userinfo?access_token={access_token}'
|
||||
headers = {'Authorization': f'Bearer {credentials.token}'}
|
||||
response = requests.get(user_info_endpoint, headers=headers)
|
||||
response.raise_for_status()
|
||||
user_info = response.json()
|
||||
print("user_info===>",user_info,'==>',type(user_info))
|
||||
email = user_info['email']
|
||||
first_name = user_info['given_name']
|
||||
last_name = user_info['family_name']
|
||||
@ -64,19 +61,16 @@ class GoogleLoginMixin:
|
||||
# ...
|
||||
user_data = User.objects.filter(email__iexact=email)
|
||||
if user_data.exists():
|
||||
print("00000000000")
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.filter(auth=user_data.last()).last()
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
if str(user_type) == '2':
|
||||
guardian_query = Guardian.objects.filter(user=user_data.last()).last()
|
||||
print("guardian_query==>",guardian_query,'====>',type(guardian_query))
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
return custom_response(SUCCESS_CODE['3003'], serializer.data,
|
||||
response_status=status.HTTP_200_OK)
|
||||
|
||||
if not User.objects.filter(email__iexact=email).exists():
|
||||
print("999999999999999")
|
||||
user_obj = User.objects.create(username=email, email=email, first_name=first_name, last_name=last_name)
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.create(auth=user_obj, is_verified=True, is_active=True,
|
||||
@ -97,7 +91,6 @@ class GoogleLoginViewSet(GoogleLoginMixin, viewsets.GenericViewSet):
|
||||
def create(self, request):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
print("88888888888888888888888888")
|
||||
return self.google_login(request)
|
||||
|
||||
class SigninWithApple(views.APIView):
|
||||
@ -109,23 +102,15 @@ class SigninWithApple(views.APIView):
|
||||
return custom_error_response(ERROR_CODE['2027'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
decoded_data = jwt.decode(token, options={"verify_signature": False})
|
||||
print("decoded_data===>",decoded_data)
|
||||
user_data = {"email": decoded_data.get('email'),"username": decoded_data.get('email'),
|
||||
"first_name": request.data.get("fullName").get("givenName"),"is_active": True,
|
||||
"last_name": request.data.get("fullName").get("familyName"),}
|
||||
if user_data['email'] and not user_data['first_name']:
|
||||
user_data['first_name'] = user_data['email'].split("@")[0]
|
||||
user_data['last_name'] = user_data['email'].split("@")[0]
|
||||
user_data = {"email": decoded_data.get('email'), "username": decoded_data.get('email'), "is_active": True}
|
||||
if decoded_data.get("email"):
|
||||
try:
|
||||
user = User.objects.get(email=decoded_data.get("email"))
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.filter(auth=user).last()
|
||||
print("junior_query==>", junior_query, '====>', type(junior_query))
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
if str(user_type) == '2':
|
||||
guardian_query = Guardian.objects.filter(user=user).last()
|
||||
print("guardian_query==>", guardian_query, '====>', type(guardian_query))
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
return custom_response(SUCCESS_CODE['3003'], serializer.data,
|
||||
response_status=status.HTTP_200_OK)
|
||||
@ -142,6 +127,7 @@ class SigninWithApple(views.APIView):
|
||||
response_status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class UpdateProfileImage(views.APIView):
|
||||
|
Reference in New Issue
Block a user