From 572cd4d710ff4db161329a87635850e059fc5ad3 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Tue, 27 Mar 2018 09:37:04 -0600 Subject: [PATCH] Update login.py --- login.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/login.py b/login.py index b50138e..e1f309d 100644 --- a/login.py +++ b/login.py @@ -1,24 +1,24 @@ -import datetime -from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker -from tabledef import * +from flask import Flask +from flask import Flask, flash, redirect, render_template, request, session, abort +import os -engine = create_engine('sqlite:///tutorial.db', echo=True) +app = Flask(__name__) -# create a Session -Session = sessionmaker(bind=engine) -session = Session() +@app.route('/') +def home(): + if not session.get('logged_in'): + return render_template('login.html') + else: + return "Hello Boss!" -user = User("admin","password") -session.add(user) +@app.route('/login', methods=['POST']) +def do_admin_login(): + if request.form['password'] == 'password' and request.form['username'] == 'admin': + session['logged_in'] = True + else: + flash('wrong password!') + return home() -user = User("python","python") -session.add(user) - -user = User("jumpiness","python") -session.add(user) - -# commit the record the database -session.commit() - -session.commit() +if __name__ == "__main__": + app.secret_key = os.urandom(12) + app.run(debug=True,host='0.0.0.0', port=4000)