update profile

This commit is contained in:
jain
2023-07-06 19:53:20 +05:30
parent 34034dcdb8
commit 2b783512a5
5 changed files with 83 additions and 30 deletions

View File

@ -23,12 +23,28 @@ class GoogleLoginSerializer(serializers.Serializer):
"""meta class"""
fields = ('access_token',)
class UpdateJuniorProfileImageSerializer(serializers.ModelSerializer):
"""Reset Password after verification"""
class Meta(object):
"""Meta info"""
model = Junior
fields = ['image']
def update(self, instance, validated_data):
"""update image """
junior_image = validated_data.get('image', instance.image)
instance.image = junior_image
instance.save()
return instance
class UpdateGuardianImageSerializer(serializers.ModelSerializer):
"""Reset Password after verification"""
class Meta(object):
"""Meta info"""
model = Guardian
fields = '__all__'
fields = ['image']
def update(self, instance, validated_data):
"""update image """
@ -36,21 +52,7 @@ class UpdateGuardianImageSerializer(serializers.ModelSerializer):
instance.save()
return instance
class UpdateJuniorProfileImageSerializer(serializers.ModelSerializer):
"""Reset Password after verification"""
class Meta(object):
"""Meta info"""
model = Junior
fields = '__all__'
def update(self, instance, validated_data):
"""update image """
image = validated_data.get('image', instance.image)
filename = f"images/{image.name}"
image_url = upload_image_to_alibaba(image, filename)
instance.image = image_url
instance.save()
return instance
class ResetPasswordSerializer(serializers.Serializer):
"""Reset Password after verification"""
verification_code = serializers.CharField(max_length=10)

View File

@ -4,7 +4,9 @@ from rest_framework import viewsets, status, views
from rest_framework.decorators import action
import random
import logging
from django.utils import timezone
import jwt
from guardian.utils import upload_image_to_alibaba
from django.contrib.auth import authenticate, login
from guardian.models import Guardian
from junior.models import Junior
@ -135,12 +137,22 @@ class SigninWithApple(views.APIView):
class UpdateProfileImage(views.APIView):
permission_classes = [IsAuthenticated]
def put(self, request, format=None):
if request.data['user_type'] == '1':
if str(request.data['user_type']) == '1':
junior_query = Junior.objects.filter(auth=request.user).last()
serializer = UpdateJuniorProfileImageSerializer(junior_query, data=request.data, partial=True)
else:
image = request.data['image']
filename = f"images/{image.name}"
image_url = upload_image_to_alibaba(image, filename)
image_data = image_url
serializer = UpdateJuniorProfileImageSerializer(junior_query,
data={'image':image_data}, partial=True)
if str(request.data['user_type']) == '2':
guardian_query = Guardian.objects.filter(user=request.user).last()
serializer = UpdateGuardianImageSerializer(guardian_query, data=request.data, partial=True)
image = request.data['image']
filename = f"images/{image.name}"
image_url = upload_image_to_alibaba(image, filename)
image_data = image_url
serializer = UpdateGuardianImageSerializer(guardian_query,
data={'image':image_data}, partial=True)
if serializer.is_valid():
serializer.save()
return custom_response(SUCCESS_CODE['3017'], serializer.data, response_status=status.HTTP_200_OK)
@ -185,7 +197,7 @@ class ForgotPasswordAPIView(views.APIView):
}
)
expiry = datetime.today() + timedelta(days=1)
expiry = timezone.now() + timezone.timedelta(days=1)
user_data, created = UserEmailOtp.objects.get_or_create(email=email)
if created:
user_data.expired_at = expiry
@ -336,7 +348,7 @@ class ReSendEmailOtp(viewsets.ModelViewSet):
def create(self, request, *args, **kwargs):
otp = generate_otp()
if User.objects.filter(email=request.data['email']):
expiry = datetime.today() + timedelta(days=1)
expiry = timezone.now() + timezone.timedelta(days=1)
email_data, created = UserEmailOtp.objects.get_or_create(email=request.data['email'])
if created:
email_data.expired_at = expiry