Ejemplo n.º 1
0
    def get(self):
        user = UserModel.objects(id=get_jwt_identity()).first()
        self.check_is_exist(user)

        return {
            'access_token': create_access_token(identity=user.id),
        }
Ejemplo n.º 2
0
    def post(self):
        payload = request.json

        id = payload['id']
        pw = payload['pw']
        email = payload['email']
        name = payload['name']

        pw_hashed = generate_password_hash(pw)

        if User.select().where(id=id) or User.select().where(email=email):
            abort(409)

        User.insert(id=id, pw_hashed=pw_hashed, email=email, name=name).execute()

        return Response('', 201)
Ejemplo n.º 3
0
    def post(self, nickname):
        owner = UserModel.objects(nickname=nickname).first()
        self.check_is_exist(owner)

        if FollowModel.objects(Q(follower=g.user) & Q(followee=owner)).first():
            return Response('', 208)

        FollowModel(follower=g.user, followee=owner).save()

        return Response('', 201)
Ejemplo n.º 4
0
    def delete(self, nickname):
        owner = UserModel.objects(nickname=nickname).first()
        self.check_is_exist(owner)

        follow = FollowModel.objects(Q(follower=g.user) & Q(followee=owner)).first()
        self.check_is_exist(follow)

        follow.delete()

        return Response('', 200)
Ejemplo n.º 5
0
    def post(self):
        payload = request.json

        id = payload['id']
        pw = payload['pw']
        name = payload['name']
        nickname = payload['nickname']
        email = payload['email']

        if UserModel.objects(id=id).first():
            abort(409)

        try:
            pw_hashed = generate_password_hash(pw)

            UserModel(id=id,
                      pw_hashed=pw_hashed,
                      name=name,
                      nickname=nickname,
                      email=email).save()
        except TypeError:
            abort(400)

        return Response('', 201)
Ejemplo n.º 6
0
    def post(self):
        payload = request.json

        user_id = payload['id']
        user_pw = payload['pw']

        user = UserModel.objects(id=user_id).first()
        self.check_is_exist(user)

        if not check_password_hash(user.pw_hashed, user_pw):
            abort(406)

        return {
            'access_token': create_access_token(user.id),
            'refresh_token': create_refresh_token(user.id)
        }, 200
Ejemplo n.º 7
0
    def get(self, nickname):
        owner = UserModel.objects(nickname=nickname).first()
        self.check_is_exist(owner)

        followers = FollowModel.objects(followee=owner).all()
        following = FollowModel.objects(follower=owner).all()

        if not followers or following:
            return Response('', 204)

        followers_list = [follow_model.follower.nickname for follow_model in followers]
        following_list = [follow_model.followee.nickname for follow_model in following]

        return self.unicode_safe_json_dumps({
            "followers": followers_list,
            "following": following_list
        })
Ejemplo n.º 8
0
    def post(self):
        """
        로그인
        """
        payload = request.json

        id = payload['id']
        pw = payload['pw']

        users = User.select().where(User.id == id)

        user = users[0]

        if not user:
            abort(401)

        if not check_password_hash(user.pw_hashed, pw):
            abort(401)

        return {
            'access_token': create_access_token(identity=id),
            'refresh_token': create_refresh_token(identity=id)
        }
Ejemplo n.º 9
0
 def wrapper(*args, **kwargs):
     user = UserModel.objects(id=get_jwt_identity()).first()
     if not user:
         abort(422)
     g.user = user
     return fn(*args, **kwargs)
Ejemplo n.º 10
0
    def get(self, my_name):
        user = UserModel.objects(nickname=my_name).first()
        self.check_is_exist(user)

        return self.unicode_safe_json_dumps({"name": user.name})
Ejemplo n.º 11
0
    def get(self, email):
        query = User.select().where(User.email == email)

        return Response('', 409 if query.exists() else 200)
Ejemplo n.º 12
0
    def get(self, id):
        query = User.select().where(User.id == id)

        return Response('', 409 if query.exists() else 200)