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)
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")
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")
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)
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)
def post(self, id): data_object = BlogModels(db_conn=get_db()) get_post(id) data_object.delete_post(id) return jsonify("True", "Deleted successfully")
def get(self): data_object = BlogModels(db_conn=get_db()) posts = data_object.fetch_posts() return jsonify(posts)
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