Exemple #1
0
def new_post():
    if not request.data:
        abort(400)
    if not get_login(request):
        abort(403)
    data = request.get_json(force=True)
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    msg = {
        "title": data.get('title', "No Title"),
        "summary": data.get('summary', ""),
        "content": data.get('content', "Placeholder Content"),
        "tags": data.get('tags', ""),
        "public": data.get('public', 0)
    }

    return json.dumps(blog.addMessage(msg), indent=2)
Exemple #2
0
def update_post(post_id):
    data = request.get_json(force=True)
    if not request.data:
        abort(400)
    if not get_login(request):
        abort(403)
    data = request.get_json(force=True)
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    msg = {
        "title": data.get('title', None),
        "summary": data.get('summary', None),
        "content": data.get('content', None),
        "tags": data.get('tags', None),
        "public": data.get('public', None)
    }

    return json.dumps(blog.editMessage(post_id, msg), indent=2)
Exemple #3
0
def get_post(post_id):
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    post = json.dumps(blog.getMessage(post_id, get_login(request)), indent=2)
    if post == "null":
        abort(404)
    return post
Exemple #4
0
def list_posts():
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    return json.dumps(blog.listMessages(showPrivate=get_login(request)),
                      indent=2)
Exemple #5
0
def show_config():
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    if get_login(request):
        return json.dumps(blog.config(), indent=2)
    else:
        abort(403)
Exemple #6
0
def delete_post(post_id):
    if not get_login(request):
        abort(403)
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    blog.deleteMessage(post_id)
    return json.dumps({"Deleted": post_id})
Exemple #7
0
    token, salt = hashedToken.split(':')
    return token == hashlib.sha256(salt.encode() +
                                   userToken.encode()).hexdigest()


def get_login(request):
    data = request.headers
    login = False
    if data.get("Authorization"):
        for t in range(len(serverConfig["tokens"])):
            if check_token(serverConfig["tokens"][t], data["Authorization"]):
                login = True
    return login


blogConfig = BlogEngine.Config(serverConfig.get("blog_id", "blog"))
route = "/" + blogConfig.get("blog_path")


@app.route(route + "/config", methods=['GET'])
def show_config():
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))
    if get_login(request):
        return json.dumps(blog.config(), indent=2)
    else:
        abort(403)


@app.route(route, methods=['GET'])
def list_posts():
    blog = BlogEngine(serverConfig.get("blog_id", "blog"))