Loggin works, as well as adding services
This commit is contained in:
parent
9c6fffe458
commit
6ab1a05271
35
app.py
35
app.py
@ -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 forms import LoginForm
|
||||
from services import Services, UserManager
|
||||
from models import User
|
||||
import sqlite3
|
||||
import re
|
||||
import datetime
|
||||
|
||||
#Setup
|
||||
app = Flask("Project Fish")
|
||||
@ -35,6 +36,9 @@ def index():
|
||||
@app.route("/GetServices", methods=['GET', 'POST'])
|
||||
def GetServices():
|
||||
nummer = (request.json)["nummer"]
|
||||
if(nummer == "-1"):
|
||||
ser=services.GetAllServices()
|
||||
return jsonify(render_template("results.html", services=ser),)
|
||||
if(not is_string_sanitized(nummer)):
|
||||
return abort(401)
|
||||
if(nummer != None and nummer != ""):
|
||||
@ -72,5 +76,32 @@ def login():
|
||||
else:
|
||||
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():
|
||||
app.run(debug=True)
|
||||
app.run(debug=True)
|
||||
|
@ -13,10 +13,49 @@ function GetServices(){
|
||||
error: function(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();
|
||||
})
|
@ -58,10 +58,6 @@
|
||||
margin-top: 0%;
|
||||
}
|
||||
|
||||
.resultitem{
|
||||
padding: .5%;
|
||||
}
|
||||
|
||||
.klanten_logo:active{
|
||||
/* -webkit-animation:spin 4s linear infinite;
|
||||
-moz-animation:spin 4s linear infinite;
|
||||
@ -119,7 +115,7 @@
|
||||
|
||||
.resultitem{
|
||||
margin: 1%;
|
||||
padding: 1;
|
||||
padding: 1%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@ -169,4 +165,31 @@
|
||||
.add_service_btn:hover{
|
||||
background-color: blue;
|
||||
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;
|
||||
}
|
@ -4,15 +4,17 @@
|
||||
|
||||
</div>
|
||||
<h1>Administratie</h1>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div class="requestblock">
|
||||
<h2>Voeg dienst toe:</h2>
|
||||
<div class="a_datum_block">
|
||||
<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 class="a_datum_block">
|
||||
<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>
|
||||
|
||||
<div class="adminresultblock" id="resultblock">
|
||||
<div class="resultblock" id="resultblock">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<form action="" method="post">
|
||||
<p><input type=text name=username>
|
||||
<p><input type=password name=password>
|
||||
<p><input type=submit value=Login>
|
||||
</form>
|
||||
<div class="requestblock">
|
||||
<form action="" method="post">
|
||||
<p><input type=text name=username style="font-size: 20px;">
|
||||
<p><input type=password name=password style="font-size: 20px;">
|
||||
<input type=submit value=Login >
|
||||
<!-- <div class="loginbutton">Login</div> -->
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -2,13 +2,22 @@
|
||||
{% for key, value in services.items() %}
|
||||
{% if(loop.index % 2 == 0) %}
|
||||
<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>
|
||||
{% else %}
|
||||
<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>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% endfor %}
|
Loading…
Reference in New Issue
Block a user