Update login.py

This commit is contained in:
Logan Hunt 2018-03-27 09:37:04 -06:00 committed by GitHub
parent a4c07273d9
commit 572cd4d710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,24 +1,24 @@
import datetime from flask import Flask
from sqlalchemy import create_engine from flask import Flask, flash, redirect, render_template, request, session, abort
from sqlalchemy.orm import sessionmaker import os
from tabledef import *
engine = create_engine('sqlite:///tutorial.db', echo=True) app = Flask(__name__)
# create a Session @app.route('/')
Session = sessionmaker(bind=engine) def home():
session = Session() if not session.get('logged_in'):
return render_template('login.html')
else:
return "Hello Boss!"
user = User("admin","password") @app.route('/login', methods=['POST'])
session.add(user) 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") if __name__ == "__main__":
session.add(user) app.secret_key = os.urandom(12)
app.run(debug=True,host='0.0.0.0', port=4000)
user = User("jumpiness","python")
session.add(user)
# commit the record the database
session.commit()
session.commit()