Merge pull request 'dev to master' (#10) from dev into master
Reviewed-on: http://192.168.178.66:3000/sulzlep/groclist/pulls/10
This commit is contained in:
+17
-6
@@ -2,21 +2,32 @@ 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}
|
||||||
|
|
||||||
mydict = {"username": username, "password": password, "groclist_uuid": uuid, "email": email, "name": full_name}
|
|
||||||
if mycol.find_one({"username": username}):
|
if db.user_cred.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")
|
||||||
|
|
||||||
|
|||||||
@@ -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})
|
||||||
|
email = db.user_info.find_one({"uuid": userid{"uuid": 1} ,"name": 1, "email": 1})
|
||||||
|
|
||||||
|
print (userid, 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,47 @@
|
|||||||
|
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 render_template("welcome.html", id=auth_user_id["uuid"])
|
||||||
|
else:
|
||||||
|
return render_template("404.html")
|
||||||
|
else:
|
||||||
|
error = "Usernaam of wachtwoord onbekend, probeer opnieuw"
|
||||||
|
return render_template("login.html", error=error)
|
||||||
|
|
||||||
|
@app.route("/welcome/<id>", methods=['GET'])
|
||||||
|
def welcome(id):
|
||||||
|
print("Hello: ", 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 %}
|
||||||
|
|||||||
@@ -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="{{
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Welcome to GrocList<h1>
|
<h2>Welcome to GrocList<h2>
|
||||||
<br>
|
<br>
|
||||||
|
Hello userid: {{ userid }}
|
||||||
<p>Click <a href="/">here</a> to go home. </p>
|
<p>Click <a href="/">here</a> to go home. </p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user