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 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)