def register(): """Register a new user. Validates that the username is not already taken. Hashes the password for security. """ if request.method == "POST": username = request.form["username"] password = request.form["password"] error = None if not username: error = "Username is required." elif not password: error = "Password is required." elif (db.execute("SELECT id FROM user WHERE username = ?", (username, )).fetchone() is not None): error = "User {0} is already registered.".format(username) if error is None: # the name is available, store it in the database and go to # the login page db.execute( "INSERT INTO user (username, password) VALUES (?, ?)", (username, generate_password_hash(password)), ) db.commit() return redirect(url_for("auth.login")) flash(error) return render_template("auth/register.html")
def add_feedback_on_tweet_classification_to_db(db, form, user_id): tweet = form['tweet_to_classify'] classification = form['classification_result'] feedback = form['result_feedback'] db.execute( "INSERT into twitter_classification_plus_feedback (author_id,data,classification,user_feedback) VALUES (?, ?,?,?)", (user_id, tweet, feedback, classification)) db.commit()
def delete(id): """Delete a post. Ensures that the post exists and that the logged in user is the author of the post. """ get_post(id) db = flaskr.db.get_db() db.execute('DELETE FROM post WHERE id = ?', (id, )) db.commit() return flask.redirect(flask.url_for('blog.index'))
def update_user_details(db, g_user, details): update_str = 'UPDATE user SET ' + ''.join([ x[0] + ' = "' + x[1] + '", ' for x in details ]) + 'username="******" where username like "' + g_user['username'] + '";' print(update_str) db.execute(update_str) db.commit() return True
def add_feedback_on_generated_text_to_db(db, form, user_id): # form['data[seed]'], form['data[length]'],form['data[method]'],form['data[output]'],form['data[rank]'] # classification = form['classification_result'] # feedback = form['result_feedback'] # text = form['output'] db.execute( "INSERT into generated_text_plus_feedback (author_id,param_method,param_length,param_output_size,seed,data,score) VALUES (?, ?,?,?,?,?,?)", (user_id, text_data.GENERATION_METHOD[form['data[method]']], len(form['data[seed]']), len(form['data[seed]']), form['data[seed]'], form['data[output]'], form['data[ranking]'])) db.commit()
def create(): if request.method == 'POST': title = request.form['title'] body = request.form['body'] error = None if not title: error = 'Title is required.' if error is not None: flash(error) else: db.execute( 'INSERT INTO post (title, body, author_id)' ' VALUES (?, ?, ?)', (title, body, g.user['id'])) db.commit() return redirect(url_for('blog.index')) return render_template('blog/create.html')
def update_post(id): post = get_post(id) if flask.request.method == 'POST': title = flask.request.form['title'] content = flask.request.form['content'] error = None if not title: error = 'Title is required' if not content: error = 'No content' if error is not None: flask.flash(error) else: db = flaskr.db.get_db() db.execute('UPDATE post SET title = ?, content = ? WHERE id = ?', (title, content, id)) db.commit() return flask.redirect(flask.url_for('blog.index')) return flask.render_template('blog/update.html', post=post)
def update(id): post = get_post(id) if request.method == 'POST': title = request.form['title'] body = request.form['body'] error = None if not title: error = 'Title is required.' if error is not None: flash(error) else: db = get_db() db.execute( 'UPDATE post SET title = ?, body = ?' ' WHERE id = ?', (title, body, id) ) db.commit() return redirect(url_for('blog.index')) return render_template('blog/update.html', post=post)
def delete(id): get_post(id) db = get_db() db.execute('DELETE FROM post WHERE id = ?', (id,)) db.commit() return redirect(url_for('blog.index'))