Beispiel #1
0
def add_post():
    if not request.json:
        return make_resp(jsonify({'message': 'Empty request'}), 400)
    elif not check_keys(request.json, ("category", "type", "title")):
        return make_resp(jsonify({'message': 'Bad request'}), 400)
    post = Post(**request.json)
    post.author = User(**get_jwt_identity())
    post = app.post_repo.request_create(post)
    return make_resp(jsonify(post), 200)
Beispiel #2
0
def user_login():
    if not request.json:
        return make_resp(jsonify({'error': 'Empty request'}), 400)
    elif not check_keys(request.json, ('username', 'password')):
        return make_resp(jsonify({'message': 'Bad request'}), 400)
    user, error = app.user_repo.authorize(request.json["username"],
                                          request.json["password"])
    if user is None:
        return make_resp(jsonify({'message': error}), 400)
    return create_jwt_generate_response(user)
Beispiel #3
0
def user_register():
    if not request.json:
        return make_resp(jsonify({'message': 'Empty request'}), 400)
    elif not check_keys(request.json, ('username', 'password')):
        return make_resp(jsonify({'message': 'Bad request'}), 400)
    created_user = app.user_repo.request_create(request.json["username"],
                                                request.json["password"])
    if created_user is None:
        return make_resp(jsonify({'message': "duplicated username"}), 400)
    return create_jwt_generate_response(created_user)
Beispiel #4
0
def add_post():
    in_json = request.json
    if not in_json:
        return make_resp(jsonify({'message': "Empty request"}), 400)
    elif not check_keys(in_json, ('category', "type", 'title')):
        return make_resp((jsonify({'message': "Bad request"})), 400)

    post = Post(**in_json)
    post.author = User(**get_jwt_identity())
    post = app.post_repo.request_create(post)
    return make_resp(jsonify(post), 200)
Beispiel #5
0
def user_login():
    in_json = request.json
    if not in_json:
        return make_resp(jsonify({'message': "Empty request"}), 400)
    elif not check_keys(in_json, ('username', "password")):
        return make_resp((jsonify({'message': "Bad request"})), 400)

    user, error = app.user_repo.authorize(**in_json)

    if user is None:
        return make_resp(jsonify({'message': error}), 400)
    return create_jwt_generate_response(user)
Beispiel #6
0
def user_register():
    in_json = request.json
    if not in_json:
        return make_resp(jsonify({'message': "Empty request"}), 400)
    elif not check_keys(in_json, ('username', "password")):
        return make_resp((jsonify({'message': "Bad request"})), 400)

    created_user = app.user_repo.request_create(**in_json)

    if created_user is None:
        return make_resp(jsonify({'message': 'Duplication user'}), 400)
    return create_jwt_generate_response(created_user)
Beispiel #7
0
def user_register():
    in_json = request.json

    if not in_json:
        return make_resp(jsonify({"message": "Empty request"}), 400)
    elif not check_keys(request.json, ('username', 'password')):
        return make_resp(jsonify({"message": "Bad request"}), 400)

    created_user = app.user_repo.request_create(**in_json)

    if created_user is None:
        return make_resp(jsonify({"message": "Duplicated user"}), 400)

    return create_jwt_generate_response(created_user)