Compare commits
10
Commits
482acca2e0
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02f3a7842a | ||
|
|
10160bceed | ||
|
|
d84027ac14 | ||
|
|
cd539a65ba | ||
|
|
095f39d7b4 | ||
|
|
93156b1bc4 | ||
|
|
8ac4d3efc0 | ||
|
|
ba40af743d | ||
|
|
e9ca0e90d5 | ||
|
|
6cc4708472 |
+19
-6
@@ -2,21 +2,34 @@ import pymongo
|
|||||||
import getpass
|
import getpass
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017/")
|
# initialize connection to database
|
||||||
|
config = {
|
||||||
|
"username": "admin",
|
||||||
|
"password": "pass",
|
||||||
|
"server": "localhost:27017",
|
||||||
|
}
|
||||||
|
connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"])
|
||||||
|
client = pymongo.MongoClient(connector)
|
||||||
|
db = client["groclist"]
|
||||||
|
|
||||||
username = input("Username: ")
|
username = input("Username: ")
|
||||||
password = getpass.getpass("Password: ")
|
password = getpass.getpass("Password: ")
|
||||||
uuid = str(uuid.uuid4())
|
uuid = str(uuid.uuid4())
|
||||||
email = input("Email-adres: ")
|
email = input("Email-adres: ")
|
||||||
full_name = input("Volledige naam: ")
|
full_name = input("Volledige naam: ")
|
||||||
|
list_id = ""
|
||||||
|
|
||||||
mydb = myclient["groclist_db"]
|
user_cred = {"username": username, "password": password, "uuid": uuid}
|
||||||
mycol = mydb["groclist_users"]
|
user_info = {"uuid":uuid, "email": email, "name": full_name ,"listid": list_id}
|
||||||
|
stores_list = {"stores_name": ["Jumbo","AH","Boons","Aldi","Lidl"]}
|
||||||
|
item_list = {"stores_name" : 1}
|
||||||
|
|
||||||
mydict = {"username": username, "password": password, "groclist_uuid": uuid, "email": email, "name": full_name}
|
if db.user_cred.find_one({"username": username}):
|
||||||
if mycol.find_one({"username": username}):
|
|
||||||
print("Username already exists\n")
|
print("Username already exists\n")
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
x = mycol.insert_one(mydict)
|
cred_record = db.user_cred.insert_one(user_cred)
|
||||||
|
info_record = db.user_info.insert_one(user_info)
|
||||||
print("User created")
|
print("User created")
|
||||||
|
|
||||||
|
stores_record = db.stores_list.insert_many(stores_list)
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import uuid
|
||||||
|
import pymongo
|
||||||
|
import getpass
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"username": "admin",
|
||||||
|
"password": "pass",
|
||||||
|
"server": "localhost:27017",
|
||||||
|
}
|
||||||
|
connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"])
|
||||||
|
client = pymongo.MongoClient(connector)
|
||||||
|
db = client["groclist"]
|
||||||
|
|
||||||
|
|
||||||
|
username = input("Username :")
|
||||||
|
#password = getpass.getpass("Password: ")
|
||||||
|
|
||||||
|
userid = db.user_cred.find_one({"username": username}, {"uuid":1, "_id":0})
|
||||||
|
email = db.user_info.find_one(userid ,{"name": 1, "email": 1, "_id":0})
|
||||||
|
|
||||||
|
print (email)
|
||||||
+14
-9
@@ -2,7 +2,10 @@ import pymongo
|
|||||||
from flask import Flask, request, render_template, url_for, redirect
|
from flask import Flask, request, render_template, url_for, redirect
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017")
|
||||||
|
mydb = myclient["groclist_db"]
|
||||||
|
mycol_users = mydb["groclist_users"]
|
||||||
|
username=""
|
||||||
|
|
||||||
@app.route("/", methods=['GET', 'POST'])
|
@app.route("/", methods=['GET', 'POST'])
|
||||||
def groclist_home():
|
def groclist_home():
|
||||||
@@ -15,26 +18,28 @@ def groclist_home():
|
|||||||
|
|
||||||
return render_template('index.html',error=error)
|
return render_template('index.html',error=error)
|
||||||
|
|
||||||
@app.route("/welcome")
|
|
||||||
def groclist_welcome():
|
|
||||||
return render_template("welcome.html")
|
|
||||||
|
|
||||||
@app.route("/login", methods=['GET', 'POST'])
|
@app.route("/login", methods=['GET', 'POST'])
|
||||||
def groclist_login():
|
def groclist_login():
|
||||||
error = None
|
error = None
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017")
|
|
||||||
mydb = myclient["groclist_db"]
|
|
||||||
mycol = mydb["groclist_users"]
|
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
password = request.form['password']
|
password = request.form['password']
|
||||||
if mycol.find_one({"username": username, "password": password}):
|
if mycol_users.find_one({"username": username, "password": password}):
|
||||||
return redirect(url_for('groclist_welcome'))
|
return redirect(url_for('groclist_welcome'))
|
||||||
else:
|
else:
|
||||||
error = 'Username of wachtwoord onbekend. Probeer opnieuw'
|
error = 'Username of wachtwoord onbekend. Probeer opnieuw'
|
||||||
|
|
||||||
return render_template("login.html", error=error)
|
return render_template("login.html", error=error)
|
||||||
|
|
||||||
|
@app.route("/welcome", methods=['GET', 'POST'])
|
||||||
|
def groclist_welcome():
|
||||||
|
if request.method == 'GET':
|
||||||
|
userid = mycol_users.find_one({"username": username}, {"_id": 1})
|
||||||
|
print(userid)
|
||||||
|
return render_template("welcome.html", userid=userid)
|
||||||
|
else:
|
||||||
|
error = "Userid is niet bekend. Database defect"
|
||||||
|
return render_template("index.html", error=error)
|
||||||
|
|
||||||
app.add_url_rule("/welcome", "welcome", groclist_welcome)
|
app.add_url_rule("/welcome", "welcome", groclist_welcome)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import pymongo
|
||||||
|
from flask import Flask, request, render_template, redirect, url_for, abort
|
||||||
|
|
||||||
|
# initialize connection to database
|
||||||
|
app = Flask(__name__)
|
||||||
|
config = {
|
||||||
|
"username": "admin",
|
||||||
|
"password": "pass",
|
||||||
|
"server": "localhost:27017",
|
||||||
|
}
|
||||||
|
connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"])
|
||||||
|
client = pymongo.MongoClient(connector)
|
||||||
|
db = client["groclist"]
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def main():
|
||||||
|
return render_template("index.html")
|
||||||
|
|
||||||
|
@app.route("/login", methods=["GET","POST"])
|
||||||
|
def login():
|
||||||
|
error = None
|
||||||
|
if request.method == "POST":
|
||||||
|
username = request.form["username"]
|
||||||
|
password = request.form["password"]
|
||||||
|
if db.user_cred.find_one({"username": username, "password": password}):
|
||||||
|
auth_user_id = db.user_cred.find_one({"username": username},{"uuid": 1})
|
||||||
|
if auth_user_id:
|
||||||
|
app.logger.info(auth_user_id)
|
||||||
|
return redirect(url_for("list", id=auth_user_id["uuid"]))
|
||||||
|
#return render_template("list.html", username=username)
|
||||||
|
else:
|
||||||
|
return redirect(url_for("not_found"))
|
||||||
|
else:
|
||||||
|
error = "Usernaam of wachtwoord onbekend, probeer opnieuw"
|
||||||
|
return render_template("login.html", error=error)
|
||||||
|
|
||||||
|
@app.route("/list/<id>", methods=['GET'])
|
||||||
|
def list(id):
|
||||||
|
get_user_record = db.user_info.find_one({"uuid": id},{"name": 1})
|
||||||
|
full_name = get_user_record["name"]
|
||||||
|
return render_template("list.html", full_name=full_name, id=id)
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def not_found(error):
|
||||||
|
app.logger.info(error)
|
||||||
|
return render_template("404.html"), 404
|
||||||
|
|
||||||
|
# start server with run method
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(debug=True)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<h2>not found</h2>
|
||||||
|
{% endblock %}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<p class="important">
|
<p class="important">
|
||||||
Welkom bij Groclist
|
Welkom bij Groclist
|
||||||
</p>
|
</p>
|
||||||
<form method="post" action="/">
|
<form method="get" action="/login">
|
||||||
<input type="submit" value="Inloggen" name="login"/>
|
<input type="submit" value="Inloggen">
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Items on your list</title>
|
||||||
|
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Welcome to GrocList<h2>
|
||||||
|
<br>
|
||||||
|
Hello {{ full_name }}
|
||||||
|
<p>Click <a href="/list/{{ id }}">List</a> to view shopping list</p>
|
||||||
|
<p>Click <a href="/">here</a> to logout. </p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<html>
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Groclist - login page</title>
|
<title>Groclist - login page</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="static/bootstrap.min.css" rel="stylesheet" media="screen">
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Please login</h1>
|
<h2>Please login</h2>
|
||||||
<br>
|
<br>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<input type="text" placeholder="Username" name="username" value="{{
|
<input type="text" placeholder="Username" name="username" value="{{
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Welcome to groclist</title>
|
|
||||||
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<h1>Welcome to GrocList<h1>
|
|
||||||
<br>
|
|
||||||
<p>Click <a href="/">here</a> to go home. </p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<html>
|
|
||||||
Reference in New Issue
Block a user