Loggin works, as well as adding services

This commit is contained in:
Eljakim Herrewijnen 2021-11-08 23:28:40 +01:00
parent 9c6fffe458
commit 6ab1a05271
7 changed files with 132 additions and 24 deletions

33
app.py
View File

@ -1,10 +1,11 @@
from flask import Flask, render_template, request, jsonify, abort, redirect, url_for from flask import *
from flask_login import LoginManager , login_required , UserMixin , login_user, current_user, logout_user from flask_login import LoginManager , login_required , UserMixin , login_user, current_user, logout_user
from forms import LoginForm from forms import LoginForm
from services import Services, UserManager from services import Services, UserManager
from models import User from models import User
import sqlite3 import sqlite3
import re import re
import datetime
#Setup #Setup
app = Flask("Project Fish") app = Flask("Project Fish")
@ -35,6 +36,9 @@ def index():
@app.route("/GetServices", methods=['GET', 'POST']) @app.route("/GetServices", methods=['GET', 'POST'])
def GetServices(): def GetServices():
nummer = (request.json)["nummer"] nummer = (request.json)["nummer"]
if(nummer == "-1"):
ser=services.GetAllServices()
return jsonify(render_template("results.html", services=ser),)
if(not is_string_sanitized(nummer)): if(not is_string_sanitized(nummer)):
return abort(401) return abort(401)
if(nummer != None and nummer != ""): if(nummer != None and nummer != ""):
@ -72,5 +76,32 @@ def login():
else: else:
return render_template("login.html") return render_template("login.html")
@app.route("/AddService", methods=["POST"])
@login_required
def AddService():
datum = (request.json)["datum"]
tijd = (request.json)["tijd"]
van = (request.json)["van"]
tot = (request.json)["tot"]
try:
van = int(van)
tot = int(tot)
groepen = ""
if(van < tot):
for i in range(van, tot, 1):
groepen += str(i)
groepen += ":"
else:
return "Invalid groups"
groepen += str(tot)
tijd = datetime.datetime.strptime(f"{datum}|{tijd}" , "%d-%m-%Y|%H:%M")
if(tijd != None):
services.AddService(tijd, str(groepen))
except:
return "500"
return "200"
def RunWeb(): def RunWeb():
app.run(debug=True) app.run(debug=True)

BIN
sqlite.db

Binary file not shown.

View File

@ -13,10 +13,49 @@ function GetServices(){
error: function(error){ error: function(error){
console.log(error); console.log(error);
} }
// success: function(result) {
// console.log("aa");
// console.log(results);
//
// }
}); });
} }
function GetAllServices(){
console.log("aa")
$.ajax({
type: "POST",
url: "/GetServices",
data: JSON.stringify({
"nummer": "-1",
}),
contentType: "application/json",
dataType: 'text json',
success: function(response) {
document.getElementById('resultblock').innerHTML = response
},
error: function(error){
console.log(error);
}
});
}
function AddService(){
$.ajax({
type: "POST",
url: "/AddService",
data: JSON.stringify({
"datum": document.getElementById('datum_input').value,
"tijd": document.getElementById('tijd_input').value,
"van": document.getElementById('van_input').value,
"tot": document.getElementById('tot_input').value,
}),
contentType: "application/json",
dataType: 'text json',
success: function(response) {
document.getElementById('resultblock').innerHTML = response
},
error: function(error){
console.log(error);
}
});
}
$(document).ready( function () {
GetAllServices();
})

View File

@ -58,10 +58,6 @@
margin-top: 0%; margin-top: 0%;
} }
.resultitem{
padding: .5%;
}
.klanten_logo:active{ .klanten_logo:active{
/* -webkit-animation:spin 4s linear infinite; /* -webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite; -moz-animation:spin 4s linear infinite;
@ -119,7 +115,7 @@
.resultitem{ .resultitem{
margin: 1%; margin: 1%;
padding: 1; padding: 1%;
text-align: center; text-align: center;
} }
@ -170,3 +166,30 @@
background-color: blue; background-color: blue;
cursor: pointer; cursor: pointer;
} }
.loginbutton{
background-color: green;
font-size: 20px;
margin: 1%;
width: 10%;
text-align: center;
padding: 1%;;
}
.loginbutton:hover{
background-color: lightgreen;
cursor: pointer;
}
.deletebutton{
position: absolute;
background-color: red;
right: 0;
font-size: medium;
padding: .5%;
margin-bottom: .5%;
right: 3%;
}
.deletebutton:hover{
background-color: orangered;
cursor: pointer;
}

View File

@ -4,8 +4,8 @@
</div> </div>
<h1>Administratie</h1> <h1>Administratie</h1>
</head>
</head>
{% block content %} {% block content %}
@ -13,6 +13,8 @@
<h2>Voeg dienst toe:</h2> <h2>Voeg dienst toe:</h2>
<div class="a_datum_block"> <div class="a_datum_block">
<input class="a_datum_input" id="datum_input" name="text" placeholder="1-11-2021"> <input class="a_datum_input" id="datum_input" name="text" placeholder="1-11-2021">
<tr>Tijd</tr>
<input class="a_datum_input" id="tijd_input" name="text" placeholder="9:30">
</div> </div>
<div class="a_datum_block"> <div class="a_datum_block">
<input class="a_van_input" id="van_input" name="text" placeholder="1"> <input class="a_van_input" id="van_input" name="text" placeholder="1">
@ -23,7 +25,7 @@
<div class="add_service_btn" onclick="AddService()">Toevoegen</div> <div class="add_service_btn" onclick="AddService()">Toevoegen</div>
</div> </div>
<div class="adminresultblock" id="resultblock"> <div class="resultblock" id="resultblock">
</div> </div>
{% endblock %} {% endblock %}

View File

@ -1,9 +1,13 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<form action="" method="post"> <div class="requestblock">
<p><input type=text name=username> <form action="" method="post">
<p><input type=password name=password> <p><input type=text name=username style="font-size: 20px;">
<p><input type=submit value=Login> <p><input type=password name=password style="font-size: 20px;">
</form> <input type=submit value=Login >
<!-- <div class="loginbutton">Login</div> -->
</form>
</div>
{% endblock %} {% endblock %}

View File

@ -2,13 +2,22 @@
{% for key, value in services.items() %} {% for key, value in services.items() %}
{% if(loop.index % 2 == 0) %} {% if(loop.index % 2 == 0) %}
<div class="resultitem" style="background-color: lightcyan"> <div class="resultitem" style="background-color: lightcyan">
Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}} uur. {% if current_user.is_authenticated %}
<div class=deletebutton>
Verwijderen
</div>
{% endif %}
Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}}:{{value[0].time().minute}} uur.
</div> </div>
{% else %} {% else %}
<div class="resultitem" style="background-color: lightblue"> <div class="resultitem" style="background-color: lightblue">
Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}} uur. {% if current_user.is_authenticated %}
<div class=deletebutton>
Verwijderen
</div>
{% endif %}
Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}}:{{value[0].time().minute}} uur.
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}