Skip to content

Commit

Permalink
Update profile info API endpoint to allow authenticated users to upda…
Browse files Browse the repository at this point in the history
…te their profile information
  • Loading branch information
Anirban-Majumder committed May 25, 2024
1 parent 2694303 commit 3f5a2dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
20 changes: 7 additions & 13 deletions aniresfr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,14 @@ def post(self, request):
raise ValidationError({'error': 'The account with that Email already exists. Please Login.'})


class UploadProfilePhoto(APIView):
permission_classes = [AllowAny]
class UpdateProfileInfo(APIView):
permission_classes = [IsAuthenticated]

def post(self, request):
email = request.data.get("email")
profile_image = request.data.get("profile_image")


try:
user = BaseUser.objects.get(email=email)
except BaseUser.DoesNotExist:
return Response({"error": "User not found"}, status=status.HTTP_404_NOT_FOUND)

user.profile_image = profile_image
user = request.user
for field in ['name', 'phone_number', 'profile_image']:
if request.data.get(field) is not None:
setattr(user, field, request.data.get(field))
user.save()

return Response({"message": "profile upload successfully"}, status=status.HTTP_200_OK)
return Response({"message": "Profile updated successfully"}, status=status.HTTP_200_OK)
3 changes: 1 addition & 2 deletions backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@
path('logout/', views.LogoutView.as_view(), name='logout'),
path('api/', include(router.urls)),
path('admin/', admin.site.urls),
path('profile/', views.UploadProfilePhoto.as_view() , name='upload profile'),

path('profile/', views.UpdateProfileInfo.as_view() , name='update profile info'),
]

0 comments on commit 3f5a2dc

Please sign in to comment.