def init_db(): with current_app.app_context(): db = get_db() with current_app.open_resource('database.db', mode='r') as f: file = f.read() db.cursor().executescript(file) db.commit()
def openDB(): db = MySQLdb.connect(host=app.config['HOST'], #hostname user=app.config['USER'], # username passwd=app.config['PW'], # password db=app.config['DB'], # db conv=my_conv,# datatype conversions cursorclass=MySQLdb.cursors.DictCursor) cur = db.cursor() return db, cur
def login(): if current_user.is_authenticated: return redirect(url_for('bkapp_page')) error = None if request.method == 'POST': userN = request.form['username'] passwN = request.form['password'] import os # DATABASE_URL = os.environ['DATABASE_URL'] import psycopg2 db = psycopg2.connect(database='brewasis', host="127.0.0.1", port="5432", password="******", user="******") c = db.cursor() c.execute("select users from login where users= '{}'".format(userN)) userN1 = c.fetchone() c.execute("select password from login where users= '{}'".format(userN)) passwN1 = c.fetchone() try: if (userN != userN1[0]) or not (bcrypt.check_password_hash( passwN1[0], passwN)): # if (userN != userN1[0]) or (passwN != passwN1[0]): error = 'Invalid Credentials. Please try again.' c.execute( "insert into loggings(users, entered)values('{}', '{}')". format(userN, 'unsuccessful')) db.commit() db.close() else: userlogin = Login.query.filter(Login.users == userN).first() login_user(userlogin) # next = flask.request.args.get('next') # # is_safe_url should check if the url is safe for redirects. # # See http://flask.pocoo.org/snippets/62/ for an example. # if not is_safe_url(next): # return flask.abort(400) # session['logged_in'] = True c.execute( "insert into loggings(users, entered)values('{}', '{}')". format(userN, 'successful')) db.commit() db.close() return redirect(url_for('bkapp_page')) except Exception as e: logging.error("Exception occurred", exc_info=True) error = 'Invalid Credentials. Please try again .' c.execute("insert into loggings(users, entered)values('{}', '{}')". format(userN, 'unsuccessful')) db.commit() db.close() return render_template('login.html', error=error)
def openDB(): db = MySQLdb.connect( host=app.config['HOST'], #hostname user=app.config['USER'], # username passwd=app.config['PW'], # password db=app.config['DB'], # db conv=my_conv, # datatype conversions cursorclass=MySQLdb.cursors.DictCursor) cur = db.cursor() return db, cur
def speakers(method): """Return a list of all speakers, ordered by number of quotes.""" c = db.cursor() c.execute('''SELECT speaker, COUNT(1) AS count FROM utterance GROUP BY speaker ORDER BY count DESC ''') result = c.fetchall() return [speaker.capitalize() for (speaker, count) in result if len(speaker) > 1]
def loggings(): import os import psycopg2 db = psycopg2.connect(database='brewasis', host="127.0.0.1", port="5432", password="******", user="******") c = db.cursor() c.execute('select * from loggings') # loggings = [dict(id=row[0],users=row[1],password=row[2],time=row[3])for row in reversed(c.fetchall())] loggings = [ dict(id=row[0], users=row[1], entered=row[3], time=row[2]) for row in reversed(c.fetchall()) ] db.close() return render_template('loggings.html', loggings=loggings)
def init_db(): """Initialize new database.""" db = get_db() with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit()