def login(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = user_services.get_and_authenticate_user(
         **serializer.validated_data)
     data = serializers.AuthUserSerializer(user).data
     return response.Ok(data)
示例#2
0
 def partial_update(self, request, post_id, comment_id):
     """Update a contact"""
     instance = services.get_comment_by_id(post_id=comment_id)
     serializer = self.get_serializer(instance, data=request.data, partial=True)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return response.Ok(serializer.data)
示例#3
0
 def partial_update(self, request, post_id):
     """Update a contact"""
     data = request.data.dict()
     user = request.user
     updated_post = services.update_post(post_id=post_id, data=data, user=user)
     ser_data = serializers.PostSerializer(updated_post).data
     return response.Ok(ser_data)
 def partial_update(self, request):
     """Update logged in user profile"""
     instance = self.get_object()
     serializer = self.get_serializer(instance,
                                      data=request.data,
                                      partial=True)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return response.Ok(serializer.data)
 def password_reset(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = user_services.get_user_by_email(serializer.data['email'])
     if user:
         services.send_password_reset_mail(user)
     return response.Ok({
         'message':
         'Further instructions will be sent to the email if it exists'
     })
示例#6
0
 def get_comments(self, request, post_id):
     comments = services.get_all_comments(post_id=post_id)
     data = serializers.CommentSerializer(comments, many=True).data
     return response.Ok(data)
示例#7
0
 def get_object(self, request, post_id):
     post = services.get_post_by_id(post_id=post_id)
     serializers_data = serializers.PostSerializer(post).data
     return response.Ok(serializers_data)
 def logout(self, request):
     """
     Calls Django logout method; Does not work for UserTokenAuth.
     """
     logout(request)
     return response.Ok({"success": "Successfully logged out."})
 def list(self, request):
     """Get logged in user profile"""
     serializer = self.get_serializer(self.get_object())
     return response.Ok(serializer.data)