Exemplo n.º 1
0
def load_logged_in_user():
    user_id = session.get('user_id')
    data_object = BlogModels(db_conn=get_db())
    if user_id is None:
        g.user = None
    else:
        g.user = data_object.get_logged_user(user_id)
Exemplo n.º 2
0
    def post(self):
        title = request.form['title']
        body = request.form['body']
        id = request.form['id']
        error = None
        data_object = BlogModels(db_conn=get_db())
        if not title:
            error = "Title is required"

        if error is not None:
            flash(error)
        else:
            data_object.insert_post(title, body, id)
            return jsonify("True")
Exemplo n.º 3
0
    def post(self, id):
        f = open("info_logs.txt", "w")
        f.write(str(request.form))
        title = request.form['title']
        body = request.form['body']
        error = None
        data_object = BlogModels(db_conn=get_db())
        if not title:
            error = "Title is required"

        if error is not None:
            flash(error)
        else:
            data_object.update_post(title, body, id)
            return jsonify("True")
Exemplo n.º 4
0
    def post(self):
        username = request.form['username']
        password = request.form['password']
        error = None
        data_object = BlogModels(get_db())
        user = data_object.get_username(username)
        if user is None:
            error = "Incorrect Username"
        elif not check_password_hash(user['password'], password):
            error = "Incorrect Password"

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            return jsonify("true")
        flash(error)
Exemplo n.º 5
0
    def post(self):
        username = request.form['username']
        password = request.form['password']
        error = None
        data_object = BlogModels(db_conn=get_db())
        if not username:
            error = "Username is required"
        elif not password:
            error = "Password is required"
        elif data_object.get_user_id(username) is not None:
            error = 'User {} is already registered.'.format(username)
        if error is None:
            data_object.insert_new_user(username, password)
            return redirect(url_for('auth.login'))

        flash(error)
Exemplo n.º 6
0
 def post(self, id):
     data_object = BlogModels(db_conn=get_db())
     get_post(id)
     data_object.delete_post(id)
     return jsonify("True", "Deleted successfully")
Exemplo n.º 7
0
 def get(self):
     data_object = BlogModels(db_conn=get_db())
     posts = data_object.fetch_posts()
     return jsonify(posts)
Exemplo n.º 8
0
def get_post(id):
    data_object = BlogModels(db_conn=get_db())
    post = data_object.fetch_post(id)
    if post is None:
        abort(404, "Post id {0} doesn't exist.".format(id))
    return post