Added bad auth
This commit is contained in:
parent
dc787e4d94
commit
1ba198f130
42
shop.py
42
shop.py
@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, render_template, make_response, request, redirect, url_for
|
from flask import Flask, render_template, make_response, request, redirect, url_for, session
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os.path
|
import os.path
|
||||||
@ -17,12 +17,16 @@ def doesDBExist(DBNAME):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def runQuery(query):
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
c = conn.cursor()
|
||||||
|
ret = c.execute(query)
|
||||||
|
conn.commit()
|
||||||
|
return ret
|
||||||
|
|
||||||
def readFromDB():
|
def readFromDB():
|
||||||
conn = sqlite3.connect(DBNAME)
|
query = '''select rowid,* from shoplist'''
|
||||||
results = conn.cursor().execute('''select rowid,* from shoplist''').fetchall()
|
return runQuery(query)
|
||||||
conn.close()
|
|
||||||
return results
|
|
||||||
|
|
||||||
def findByName(name):
|
def findByName(name):
|
||||||
conn = sqlite3.connect(DBNAME)
|
conn = sqlite3.connect(DBNAME)
|
||||||
@ -33,35 +37,27 @@ def findByName(name):
|
|||||||
|
|
||||||
def insertToDB(data):
|
def insertToDB(data):
|
||||||
query = f"INSERT INTO SHOPLIST VALUES (\"{data['item']}\", 0, 0, \"{data['name']}\")"
|
query = f"INSERT INTO SHOPLIST VALUES (\"{data['item']}\", 0, 0, \"{data['name']}\")"
|
||||||
print(query)
|
runQuery(query)
|
||||||
conn = sqlite3.connect(DBNAME)
|
|
||||||
c = conn.cursor()
|
|
||||||
c.execute(query)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
|
|
||||||
def deleteRow(rowID):
|
def deleteRow(rowID):
|
||||||
query = f"DELETE FROM SHOPLIST WHERE ROWID = {rowID}"
|
query = f"DELETE FROM SHOPLIST WHERE ROWID = {rowID}"
|
||||||
conn = sqlite3.connect(DBNAME)
|
runQuery(query)
|
||||||
c = conn.cursor()
|
|
||||||
c.execute(query)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
def getItem(rowID):
|
def getItem(rowID):
|
||||||
query = f"UPDATE shoplist set gotten = 1 where rowid = {rowID}"
|
query = f"UPDATE shoplist set gotten = 1 where rowid = {rowID}"
|
||||||
conn = sqlite3.connect(DBNAME)
|
runQuery(query)
|
||||||
c = conn.cursor()
|
|
||||||
c.execute(query)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config["DEBUG"] = True
|
app.config["DEBUG"] = True
|
||||||
|
app.secret_key = b'*$#@U9423jr92jioJKL_)_;dasfj()12'
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
if 'allowed' not in session:
|
||||||
|
data = {"title":"Login"}
|
||||||
|
return render_template("auth.html", data=data)
|
||||||
|
|
||||||
query = readFromDB()
|
query = readFromDB()
|
||||||
data = {"title":"Shopping List", "results":query}
|
data = {"title":"Shopping List", "results":query}
|
||||||
for device in MOBILES:
|
for device in MOBILES:
|
||||||
@ -85,6 +81,10 @@ def handle_data():
|
|||||||
if "got" in request.form:
|
if "got" in request.form:
|
||||||
getItem(request.form["got"])
|
getItem(request.form["got"])
|
||||||
|
|
||||||
|
if "loginform" in request.form:
|
||||||
|
if request.form["password"] == "theloves2020":
|
||||||
|
session["allowed"] = "allowed"
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
30
templates/auth.html
Normal file
30
templates/auth.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Shopping List</title>
|
||||||
|
<!-- Latest compiled and minified CSS -->
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<link rel="stylesheet" content="text/css" href="/static/css/main.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 class="container" style="text-align: center">{{ data["title"] }}</h1>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<form style="text-align: center" action="/post" method="POST">
|
||||||
|
<input type="password" name="password"/>
|
||||||
|
<input type="submit" name="loginform" value="Login" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- jQuery library -->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Popper JS -->
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Latest compiled JavaScript -->
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -9,7 +9,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 class="container" style="text-align: center">{{ data["title"] }}</h1>
|
<h1 class="container" style="text-align: center">{{ data["title"] }}</h1>
|
||||||
<div class="" style="; text-align: center">
|
<div class="" style=" text-align: center">
|
||||||
<form action="/post" method="post">
|
<form action="/post" method="post">
|
||||||
Name: <input type="text" name="name" value=""><br>
|
Name: <input type="text" name="name" value=""><br>
|
||||||
Item: <input type="text" name="item" value=""><br><br>
|
Item: <input type="text" name="item" value=""><br><br>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user