Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        try:
            json_str=((request.body).decode('utf-8'))
            json_obj=json.loads(json_str)
        except JSONDecodeError:
            error = OutResponse.invalid_input_params().data
            return HttpResponse(json.dumps(error), content_type='application/json')

        if not validation_utils.check_args(json_obj,('refresh_token',)):
            error = OutResponse.missing_input_params().data
            return HttpResponse(json.dumps(error), content_type='application/json')

        request.POST = { "grant_type" : "refresh_token", "refresh_token" : json_obj["refresh_token"] }
        response = super(Refresh, self).post(request,args,kwargs)
        content = response.content.decode('utf-8')
        content = json.loads(content)

        if response.status_code == 200:
            content.pop("scope", None)
            content.pop("expires_in", None)
            content.pop("token_type", None)
            content = OutResponse.action_performed(content).data

        if response.status_code == 401:
            content = 'Invalid Credentials'
            content = OutResponse.invalid_input_params(content).data

        content = json.dumps(content)
        response.content = content.encode('utf-8')
        return response

#TODO : UpdatePassword, ManageSessions etc... here
Esempio n. 2
0
    def post(self, request, *args, **kwargs):
        try:
            json_str=((request.body).decode('utf-8'))
            json_obj=json.loads(json_str)
        except JSONDecodeError:
            error = OutResponse.invalid_input_params().data
            return HttpResponse(json.dumps(error), content_type='application/json')

        if not validation_utils.check_args(json_obj,('username', 'password')):
            error = OutResponse.missing_input_params().data
            return HttpResponse(json.dumps(error), content_type='application/json')

        request.POST = { "grant_type" : "password", "scope" : "spot_guy",
                         "username" : json_obj["username"], "password" : json_obj["password"] }
        response = super(Login, self).post(request,args,kwargs)
        content = response.content.decode('utf-8')
        content = json.loads(content)

        if response.status_code == 200:
            content.pop("scope", None)
            content.pop("expires_in", None)
            content.pop("token_type", None)
            content = OutResponse.action_performed(content).data

        if response.status_code == 401:
            content = 'Invalid Credentials'
            content = OutResponse.invalid_input_params(content).data

        content = json.dumps(content)
        response.content = content.encode('utf-8')
        return response
Esempio n. 3
0
    def handle_profile_picture(self):
        try:
            actual_profile = Profile.objects.get(account=self.request.user.id)
            serializer = ProfilePictureSerializer(actual_profile,data=self.request.data)
            if serializer.is_valid():
                serializer.save()
                return OutResponse.content_updated()
            return OutResponse.invalid_input_params(serializer.errors)

        except ObjectDoesNotExist:
            return OutResponse.content_not_matched()
Esempio n. 4
0
    def handle_profile_picture(self):
        try:
            actual_profile = Profile.objects.get(account=self.request.user.id)
            serializer = ProfilePictureSerializer(actual_profile,
                                                  data=self.request.data)
            if serializer.is_valid():
                serializer.save()
                return OutResponse.content_updated()
            return OutResponse.invalid_input_params(serializer.errors)

        except ObjectDoesNotExist:
            return OutResponse.content_not_matched()
Esempio n. 5
0
    def post(self, request, *args, **kwargs):
        try:
            json_str = ((request.body).decode('utf-8'))
            json_obj = json.loads(json_str)
        except JSONDecodeError:
            error = OutResponse.invalid_input_params().data
            return HttpResponse(json.dumps(error),
                                content_type='application/json')

        if not validation_utils.check_args(json_obj, ('refresh_token', )):
            error = OutResponse.missing_input_params().data
            return HttpResponse(json.dumps(error),
                                content_type='application/json')

        request.POST = {
            "grant_type": "refresh_token",
            "refresh_token": json_obj["refresh_token"]
        }
        response = super(Refresh, self).post(request, args, kwargs)
        content = response.content.decode('utf-8')
        content = json.loads(content)

        if response.status_code == 200:
            content.pop("scope", None)
            content.pop("expires_in", None)
            content.pop("token_type", None)
            content = OutResponse.action_performed(content).data

        if response.status_code == 401:
            content = 'Invalid Credentials'
            content = OutResponse.invalid_input_params(content).data

        content = json.dumps(content)
        response.content = content.encode('utf-8')
        return response


#TODO : UpdatePassword, ManageSessions etc... here
Esempio n. 6
0
    def handle_spot(self):
        try:
            if self.content_id is None:
                return OutResponse.invalid_arguments()

            actual_spot = Spot.all_objects.get(id=self.content_id,created_by=self.request.user.id)
            serializer = SpotMainPicSerializer(actual_spot, data=self.request.data)
            if serializer.is_valid():
                serializer.save()
                PendingMedia.update_pending_media(Spot.MEDIA_TYPE, self.content_id, 1)
                return OutResponse.content_updated()
            return OutResponse.invalid_input_params(serializer.errors)
        except ObjectDoesNotExist:
            return OutResponse.content_not_matched()
Esempio n. 7
0
    def post(self, request, *args, **kwargs):
        try:
            json_str = ((request.body).decode('utf-8'))
            json_obj = json.loads(json_str)
        except JSONDecodeError:
            error = OutResponse.invalid_input_params().data
            return HttpResponse(json.dumps(error),
                                content_type='application/json')

        if not validation_utils.check_args(json_obj, ('username', 'password')):
            error = OutResponse.missing_input_params().data
            return HttpResponse(json.dumps(error),
                                content_type='application/json')

        request.POST = {
            "grant_type": "password",
            "scope": "spot_guy",
            "username": json_obj["username"],
            "password": json_obj["password"]
        }
        response = super(Login, self).post(request, args, kwargs)
        content = response.content.decode('utf-8')
        content = json.loads(content)

        if response.status_code == 200:
            content.pop("scope", None)
            content.pop("expires_in", None)
            content.pop("token_type", None)
            content = OutResponse.action_performed(content).data

        if response.status_code == 401:
            content = 'Invalid Credentials'
            content = OutResponse.invalid_input_params(content).data

        content = json.dumps(content)
        response.content = content.encode('utf-8')
        return response
Esempio n. 8
0
    def handle_spot(self):
        try:
            if self.content_id is None:
                return OutResponse.invalid_arguments()

            actual_spot = Spot.all_objects.get(id=self.content_id,
                                               created_by=self.request.user.id)
            serializer = SpotMainPicSerializer(actual_spot,
                                               data=self.request.data)
            if serializer.is_valid():
                serializer.save()
                PendingMedia.update_pending_media(Spot.MEDIA_TYPE,
                                                  self.content_id, 1)
                return OutResponse.content_updated()
            return OutResponse.invalid_input_params(serializer.errors)
        except ObjectDoesNotExist:
            return OutResponse.content_not_matched()
Esempio n. 9
0
 def post(self, request):
     serializer = SpotSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save(created_by=self.request.user)
         return OutResponse.content_created_pending_media(serializer.data)
     return OutResponse.invalid_input_params(serializer.errors)
Esempio n. 10
0
 def post(self, request, format=None):
     serializer = SignUpSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return OutResponse.content_created()
     return OutResponse.invalid_input_params(serializer.errors)
Esempio n. 11
0
 def post(self, request, format=None):
     serializer = SignUpSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return OutResponse.content_created()
     return OutResponse.invalid_input_params(serializer.errors)
Esempio n. 12
0
 def post(self, request):
     serializer = SpotSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save(created_by=self.request.user)
         return OutResponse.content_created_pending_media(serializer.data)
     return OutResponse.invalid_input_params(serializer.errors)