Exemplo n.º 1
0
    def delete(self, username):
        RequestValidator.validate_request(DeleteUserSchema(), request.json)

        user = UserService.get_user_by_username(username)
        password = request.json.get("password")

        UserService.raise_401_if_not_password_verified(user, password=password)
        user.delete_user()

        return {}, 200
Exemplo n.º 2
0
    def put(self, username):
        RequestValidator.validate_request(AccountChangePasswordInputSchema(),
                                          request.json)

        json = request.json
        user = UserService.get_user_by_username(username)
        password = json["password"]
        new_password = json["new_password"]

        UserService.raise_401_if_not_password_verified(user, password)
        AccountService.change_account_password(user, new_password)

        return {}, 200
Exemplo n.º 3
0
    def get(self):
        post_id = request.args.get("post-id", None)
        username = request.args.get("username", None)
        page = request.args.get("page", default=1, type=int)
        per_page = request.args.get("per-page", default=20, type=int)

        if post_id is not None and username is not None:
            abort(
                400,
                "post_id and username cant be given together, u must give one of both"
            )
        elif post_id is None and username is None:
            abort(400, "Parameter missed")

        post = None
        user = None

        if post_id:
            post = PostService.get_post_by_post_id(post_id)
        if username:
            user = UserService.get_user_by_username(username)

        paged_comments = CommentListService.get_paginated_comments(
            post=post, user=user, page=page, per_page=per_page)

        return {
            "comments": comments_schema.dump(paged_comments.items),
            "number_of_pages": paged_comments.pages,
        }, 200
Exemplo n.º 4
0
    def post(self, post_id):
        request_user = UserService.get_user_by_email_or_none(
            get_jwt_identity())
        validate_post_id(post_id)

        self.postlike_service.abort_409_if_postlike_exists(
            user_id=request_user.email, post_id=post_id)
        self.postdislike_service.abort_409_if_postdislike_exists(
            user_id=request_user.email, post_id=post_id)

        self.postdislike_service.create_postdislike(post_id=post_id,
                                                    user_id=request_user.email)

        number_of_dislikes = \
            len(self.postdislike_service.get_postdislikes_by_post_id(post_id))

        return {"number_of_dislikes": number_of_dislikes}, 201
        '''
            validate_post_id

            check_postlike_or_postdislike_already_exist
                if exist abort 409
            
            create postlike by user
            response 201, number_of_likes
        '''
        pass
Exemplo n.º 5
0
    def delete(self, post_id):
        request_user = UserService.get_user_by_email_or_none(
            get_jwt_identity())
        validate_post_id(post_id)

        postlike_to_delete = \
            self.postlike_service.get_postlike_or_abort_404(
                user_id=request_user.email,
                post_id=post_id
            )

        postlike_to_delete.delete()

        number_of_likes = \
            len(self.postlike_service.get_postlikes_by_post_id(post_id))

        return {"number_of_likes": number_of_likes}, 200
        '''
            validate_post_id

            check_is_postlike_by_request_user_exist
                if not exist abort 404
                else get postlike
            
            delete postlike
            
            response 200, number_of_likes
        '''
        pass
Exemplo n.º 6
0
    def put(self, username):
        user = UserService.get_user_by_username(username)
        json = request.json

        RequestValidator.validate_request(UserPutInputSchema(), json)
        AccountService.check_exist_same_username(json["username"])

        UserService.update_user(
            user=user,
            username=json["username"],
            explain=json["user_explain"],
            email=user.email,
            profile_image=user.profile_image,
            password_hash=user.password_hash,
        )

        return {}, 200
Exemplo n.º 7
0
    def get(self):
        RequestValidator.validate_request(GetUsernameDuplicationSchema(),
                                          request.args)
        username = request.args["username"]

        usable = UserService.get_user_by_username_or_none(username) is None

        return {"usable": usable}, 200
Exemplo n.º 8
0
    def get(self):
        RequestValidator.validate_request(GetEmailDuplicationSchema(),
                                          request.args)
        email = request.args["email"]

        usable = UserService.get_user_by_email_or_none(email) is None

        return {"usable": usable}, 200
Exemplo n.º 9
0
def test_email_verify_success_response_200_and_create_user(
        client, test_registration):
    rv = post_email_verification_code(client,
                                      test_registration["verification_code"])

    assert rv.status_code == 200
    assert (UserService.get_user_by_username_or_none(
        test_registration["user"].username) is not None)
Exemplo n.º 10
0
    def post(self):
        RequestValidator.validate_request(PostTokenValidateSchema(),
                                          request.json)
        email = request.json.get("email")
        password = request.json.get("password")

        login_user = UserService.get_user_by_email_or_none(email)

        if login_user and login_user.verify_password(password):
            return {"access_token": login_user.generate_access_token()}, 201

        abort(401, "incorrect username or password")
Exemplo n.º 11
0
    def post(self, post_id):
        request_user = UserService.get_user_by_email_or_none(
            get_jwt_identity())
        validate_post_id(post_id)

        self.postlike_service.abort_409_if_postlike_exists(
            user_id=request_user.email, post_id=post_id)
        self.postdislike_service.abort_409_if_postdislike_exists(
            user_id=request_user.email, post_id=post_id)

        self.postlike_service.create_postlike(post_id=post_id,
                                              user_id=request_user.email)

        number_of_likes = \
            len(self.postlike_service.get_postlikes_by_post_id(post_id))

        return {"number_of_likes": number_of_likes}, 201
        '''
Exemplo n.º 12
0
    def get(self):
        RequestValidator.validate_request(
            PostGetQueryParameterValidateSchema(), request.args)

        gallery_id = request.args.get(key="gallery-id", default=None, type=str)
        username = request.args.get(key="username", default=None, type=str)
        page = request.args.get(key="page", default=1, type=int)
        per_page = request.args.get(key="per-page", default=20, type=int)

        gallery = GalleryService.get_gallery_by_id(
            gallery_id) if gallery_id else None
        user = UserService.get_user_by_username(username) if username else None

        paged_posts = PostListService.get_paginated_posts(gallery=gallery,
                                                          user=user,
                                                          page=page,
                                                          per_page=per_page)

        return {
            "posts": posts_schema.dump(paged_posts.items),
            "number_of_pages": paged_posts.pages,
        }, 200
Exemplo n.º 13
0
 def get(self, username):
     return (
         user_schema.dump(UserService.get_user_by_username(username)),
         200,
     )
Exemplo n.º 14
0
    def get(self):
        user = UserService.get_user_by_email_or_none(get_jwt_identity())

        return user_schema.dump(user)
Exemplo n.º 15
0
 def get(self, username):
     user = UserService.get_user_by_username(username)
     return account_schema.dump(user), 200