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,('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. 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,('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. 3
0
    def get(self,request, username = None):

        try:
            inUser = request.user if username is None else MyUser.objects.get(username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()
        a = "a"
        serializer = MainProfileSerializer(inUser,context={'username': self.request.user})
        return OutResponse.unit_set(serializer.data)
Esempio n. 4
0
    def get(self, request, username=None):

        try:
            inUser = request.user if username is None else MyUser.objects.get(
                username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()
        a = "a"
        serializer = MainProfileSerializer(
            inUser, context={'username': self.request.user})
        return OutResponse.unit_set(serializer.data)
Esempio n. 5
0
    def put(self, request, username = None):
        if username is not None:
            return OutResponse.page_not_found()

        profile = Profile.objects.get(account=self.request.user)

        serializer = UserProfileSerializer(profile, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return OutResponse.content_updated()
        return Response(validation_utils.output_error(validation_messages.invalid_input_params,serializer.errors), status=status.HTTP_400_BAD_REQUEST)
Esempio n. 6
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. 7
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. 8
0
    def delete(self, request, username):

        try:
            inUser = request.user
            otherUser = MyUser.objects.get(username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        _status = FollowerRelation.do_unfollow(inUser,otherUser)
        if not _status:
            return OutResponse.entry_not_existent()

        return OutResponse.content_deleted(_status)
Esempio n. 9
0
    def delete(self, request, username):

        try:
            inUser = request.user
            otherUser = MyUser.objects.get(username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        _status = FollowerRelation.do_unfollow(inUser, otherUser)
        if not _status:
            return OutResponse.entry_not_existent()

        return OutResponse.content_deleted(_status)
Esempio n. 10
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. 11
0
    def get(self, request,spot = None, username = None):
        if spot is not None:
            return OutResponse.page_not_found()

        try:
            inUser = request.user if username is None else MyUser.objects.get(username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        ret = Favorites.get_spot(inUser)

        if len(ret) == 0:
            return OutResponse.empty_set()

        return OutResponse.content_set(ret)
Esempio n. 12
0
    def post(self, request,spot, username =None):
        if username is not None:
            return OutResponse.page_not_found()

        try:
            inUser = request.user
            inSpot = Spot.objects.get(id=spot)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        create = Favorites.create_favorite(inUser,inSpot)
        if not create:
            return OutResponse.entry_already_exists()

        return OutResponse.content_created(create)
Esempio n. 13
0
    def delete(self, request,spot, username = None):
        if username is not None:
            return OutResponse.page_not_found()

        try:
            inUser = request.user
            inSpot = Spot.objects.get(id=spot)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        _status = Favorites.delete_favorite(inUser,inSpot)
        if not _status:
            return OutResponse.entry_not_existent()

        return OutResponse.content_deleted()
Esempio n. 14
0
    def delete(self, request, spot, username=None):
        if username is not None:
            return OutResponse.page_not_found()

        try:
            inUser = request.user
            inSpot = Spot.objects.get(id=spot)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        _status = Favorites.delete_favorite(inUser, inSpot)
        if not _status:
            return OutResponse.entry_not_existent()

        return OutResponse.content_deleted()
Esempio n. 15
0
    def post(self, request, spot, username=None):
        if username is not None:
            return OutResponse.page_not_found()

        try:
            inUser = request.user
            inSpot = Spot.objects.get(id=spot)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        create = Favorites.create_favorite(inUser, inSpot)
        if not create:
            return OutResponse.entry_already_exists()

        return OutResponse.content_created(create)
Esempio n. 16
0
    def get(self, request, base64string):
        if base64string is None:
            #TODO: Get queryParams - do something without search
            decoded = None
        else:
            try:
                decoded = base64.b64decode(base64string).decode('utf-8')
            except binascii.Error:
                return OutResponse.invalid_arguments()

        search_results = spot_search(decoded)
        if len(search_results) == 0:
            return OutResponse.empty_set()

        return OutResponse.content_set(search_results)
Esempio n. 17
0
    def get(self, request, base64string):
        if base64string is None:
            #TODO: Get queryParams - do something without search
            decoded = None
        else:
            try:
                decoded = base64.b64decode(base64string).decode('utf-8')
            except binascii.Error:
                return OutResponse.invalid_arguments()

        search_results = user_search(decoded, request.user.username)
        if len(search_results) == 0:
            return OutResponse.empty_set()

        return OutResponse.content_set(search_results)
Esempio n. 18
0
    def put(self, request, username=None):
        if username is not None:
            return OutResponse.page_not_found()

        profile = Profile.objects.get(account=self.request.user)

        serializer = UserProfileSerializer(profile,
                                           data=request.data,
                                           partial=True)
        if serializer.is_valid():
            serializer.save()
            return OutResponse.content_updated()
        return Response(validation_utils.output_error(
            validation_messages.invalid_input_params, serializer.errors),
                        status=status.HTTP_400_BAD_REQUEST)
Esempio n. 19
0
    def get(self, request, spot=None, username=None):
        if spot is not None:
            return OutResponse.page_not_found()

        try:
            inUser = request.user if username is None else MyUser.objects.get(
                username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        ret = Favorites.get_spot(inUser)

        if len(ret) == 0:
            return OutResponse.empty_set()

        return OutResponse.content_set(ret)
Esempio n. 20
0
    def get(self, request, username=None, following=False):

        try:
            inUser = request.user if username is None else MyUser.objects.get(username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        if following:
            ret = FollowerRelation.get_following(inUser)
        else:
            ret = FollowerRelation.get_follows(inUser)

        if len(ret) == 0:
            return OutResponse.empty_set()

        return OutResponse.content_set(ret)
Esempio n. 21
0
 def post(self, request, media_type, content_id):
     self.content_id = content_id
     self.request = request
     type_cases = {
         Spot.MEDIA_TYPE: self.handle_spot(),
         Profile.MEDIA_TYPE: self.handle_profile_picture()
     }
     return type_cases.get(media_type, OutResponse.invalid_arguments("wrong_media_type"))
Esempio n. 22
0
    def get(self, request, username=None, following=False):

        try:
            inUser = request.user if username is None else MyUser.objects.get(
                username=username)
        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        if following:
            ret = FollowerRelation.get_following(inUser)
        else:
            ret = FollowerRelation.get_follows(inUser)

        if len(ret) == 0:
            return OutResponse.empty_set()

        return OutResponse.content_set(ret)
Esempio n. 23
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. 24
0
 def post(self, request, media_type, content_id):
     self.content_id = content_id
     self.request = request
     type_cases = {
         Spot.MEDIA_TYPE: self.handle_spot(),
         Profile.MEDIA_TYPE: self.handle_profile_picture()
     }
     return type_cases.get(
         media_type, OutResponse.invalid_arguments("wrong_media_type"))
Esempio n. 25
0
    def post(self, request, username):

        try:
            inUser = request.user
            otherUser = MyUser.objects.get(username=username)

            if inUser.username == username:
                return OutResponse.invalid_arguments()

        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        same_follow_relation = FollowerRelation.objects.filter(user_created=inUser, user_following=otherUser)
        if same_follow_relation.exists():
            return OutResponse.entry_already_exists()

        _status = FollowerRelation.do_follow(inUser,otherUser)

        return OutResponse.content_created(_status)
Esempio n. 26
0
    def post(self, request, username):

        try:
            inUser = request.user
            otherUser = MyUser.objects.get(username=username)

            if inUser.username == username:
                return OutResponse.invalid_arguments()

        except ObjectDoesNotExist:
            return OutResponse.invalid_arguments()

        same_follow_relation = FollowerRelation.objects.filter(
            user_created=inUser, user_following=otherUser)
        if same_follow_relation.exists():
            return OutResponse.entry_already_exists()

        _status = FollowerRelation.do_follow(inUser, otherUser)

        return OutResponse.content_created(_status)
Esempio n. 27
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. 28
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. 29
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. 30
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. 31
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. 32
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)