Example #1
0
 def update_me(self, request):
     """Update current user."""
     serializer = UserProfileFullSerializer(
         request.user.profile,
         data=request.data,
         context=self.get_serializer_context())
     if not serializer.is_valid():
         return Response({'error': 'validation failed'}, status=400)
     serializer.save()
     return Response(serializer.data)
Example #2
0
    def update_me(self, request):
        """Update current user."""
        # Create device instead of updating profile
        if 'fcm_id' in request.data:
            update_fcm_device(request, request.data.pop('fcm_id', None))

        serializer = UserProfileFullSerializer(
            request.user.profile,
            data=request.data,
            context=self.get_serializer_context())
        if not serializer.is_valid():
            return Response(serializer.errors, status=400)
        serializer.save()
        return Response(serializer.data)
Example #3
0
    def update_me(self, request):
        """Update current user."""
        # Create device instead of updating profile
        if 'fcm_id' in request.data:
            update_fcm_device(request, request.data.pop('fcm_id', None))

        # Check if all fields are exposed ones
        if any(f not in UserProfile.ExMeta.user_editable
               for f in request.data):
            return forbidden_no_privileges()

        # Count as a ping
        profile = request.user.profile
        profile.last_ping = timezone.now()
        profile.active = True

        serializer = UserProfileFullSerializer(
            profile, data=request.data, context=self.get_serializer_context())
        if not serializer.is_valid():
            return Response(serializer.errors, status=400)
        serializer.save()
        return Response(serializer.data)