Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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'
     })
Ejemplo n.º 4
0
 def partial_update(self, request, *args, **kargs):
     serializer_class = self.get_serializer_class()
     instance = self.get_object()
     if 'region_coordinates' in request.data:
         request.data['region_coordinates'] = get_polygon_object(
             request.data['region_coordinates'])
     serializer = serializer_class(instance, request.data, partial=True)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return response.Ok(serializer.data)
Ejemplo n.º 5
0
 def search(self, request, *args, **kargs):
     if 'longitude' not in request.data or 'latitude' not in request.data:
         return response.BadRequest(
             {"error": "Both 'longitude' and 'latitude' required"})
     else:
         if type(request.data['longitude']) != float or type(
                 request.data['latitude']) != float:
             return response.BadRequest({
                 "error":
                 "Both 'longitude' and 'latitude' should be of type float"
             })
         else:
             point_object = Point(
                 [request.data['longitude'], request.data['latitude']])
             queryset = self.get_queryset()
             for region in queryset:
                 if not region.is_coordinate_inclusive(point_object):
                     queryset = queryset.exclude(id=region.id)
             serializer = self.get_serializer(queryset, many=True)
             return response.Ok(serializer.data)
Ejemplo n.º 6
0
 def all(self, request):
     """Listing all the active users"""
     serializer = self.get_serializer(self.queryset, many=True)
     return response.Ok(serializer.data)
Ejemplo n.º 7
0
 def list(self, request):
     """Get logged in user profile"""
     serializer = self.get_serializer(self.get_object())
     return response.Ok(serializer.data)
Ejemplo n.º 8
0
 def logout(self, request):
     """
     Calls Django logout method; Does not work for UserTokenAuth.
     """
     logout(request)
     return response.Ok({"success": "Successfully logged out."})