Make ampel aware of the order in bearbeiter.txt
Technically this commit makes ampel way more fragile. It now uses an array to store each employee and identifies employees now by the index of this array. All this requires everything to be in order (e.g. the dropdown in the login - if this is out of order, then login results in another user than the displayed one). This was just a simple solution which works way to good. An alternative whould be of cause another entry in the previously used dict which shows an index.
This commit is contained in:
parent
f24b6b5136
commit
0b9b781fef
2 changed files with 27 additions and 15 deletions
38
ampel.py
38
ampel.py
|
@ -3,7 +3,6 @@ import bottle
|
||||||
import json
|
import json
|
||||||
from bottle import route, post, run, template, static_file, request, response, redirect
|
from bottle import route, post, run, template, static_file, request, response, redirect
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import pdb
|
|
||||||
|
|
||||||
@route("/")
|
@route("/")
|
||||||
def index():
|
def index():
|
||||||
|
@ -13,7 +12,8 @@ def index():
|
||||||
def login():
|
def login():
|
||||||
global employees
|
global employees
|
||||||
if request.get_cookie("employeeId") is None:
|
if request.get_cookie("employeeId") is None:
|
||||||
return template("login", employees=sorted(employees.items(), key=lambda entry: entry[0]))
|
return template("login", employees=employees)
|
||||||
|
#return template("login", employees=sorted(employees.items(), key=lambda entry: entry[0]))
|
||||||
else:
|
else:
|
||||||
redirect("/manage")
|
redirect("/manage")
|
||||||
|
|
||||||
|
@ -21,31 +21,43 @@ def login():
|
||||||
def loginUser():
|
def loginUser():
|
||||||
global employees
|
global employees
|
||||||
employeeId = request.forms.get("employeeId")
|
employeeId = request.forms.get("employeeId")
|
||||||
employee = employees[employeeId]
|
response.set_cookie("employeeId", employeeId , max_age=60*60*24*365*10)
|
||||||
response.set_cookie("employeeId", employeeId, max_age=60*60*24*365*10)
|
|
||||||
redirect("/manage")
|
redirect("/manage")
|
||||||
|
|
||||||
|
def loggedIn():
|
||||||
|
try:
|
||||||
|
employeeId = int(request.get_cookie("employeeId"))
|
||||||
|
except ValueError:
|
||||||
|
employeeId = None
|
||||||
|
if employeeId is None or employeeId > len(employees) or employeeId < 0:
|
||||||
|
response.set_cookie("employeeId", "") #clear cookie
|
||||||
|
redirect("/login")
|
||||||
|
else:
|
||||||
|
return employeeId
|
||||||
|
|
||||||
@post("/logout")
|
@post("/logout")
|
||||||
def logout():
|
def logout():
|
||||||
|
employeeId = loggedIn()
|
||||||
|
if employeeId >= 0:
|
||||||
|
global employees
|
||||||
|
loggedOut = list(employees[employeeId])
|
||||||
|
loggedOut[2] = False #sets status to not available
|
||||||
|
employees[employeeId] = loggedOut
|
||||||
response.set_cookie("employeeId", "") #clear cookie
|
response.set_cookie("employeeId", "") #clear cookie
|
||||||
redirect("/login")
|
redirect("/login")
|
||||||
|
|
||||||
@route("/manage")
|
@route("/manage")
|
||||||
def manage():
|
def manage():
|
||||||
global employees
|
global employees
|
||||||
if request.get_cookie("employeeId") is None or request.get_cookie("employeeId") not in employees:
|
employeeId = loggedIn()
|
||||||
response.set_cookie("employeeId", "") #clear cookie
|
if employeeId >= 0:
|
||||||
redirect("/login")
|
return template("manage", employeeData=employees[employeeId])
|
||||||
else:
|
|
||||||
return template("manage", employeeData=employees[request.get_cookie("employeeId")])
|
|
||||||
|
|
||||||
@post("/setStatus")
|
@post("/setStatus")
|
||||||
def setStatus():
|
def setStatus():
|
||||||
if request.get_cookie("employeeId") is None:
|
employeeId = loggedIn()
|
||||||
redirect("/login")
|
if employeeId >= 0:
|
||||||
else:
|
|
||||||
global employees
|
global employees
|
||||||
employeeId = request.get_cookie("employeeId")
|
|
||||||
newStatus = list(employees[employeeId])
|
newStatus = list(employees[employeeId])
|
||||||
newStatus[2] = not newStatus[2] #toggle availability
|
newStatus[2] = not newStatus[2] #toggle availability
|
||||||
employees[employeeId] = newStatus
|
employees[employeeId] = newStatus
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
<div>Login für Mitarbeiter:</div>
|
<div>Login für Mitarbeiter:</div>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<select name="employeeId">
|
<select name="employeeId">
|
||||||
% for employee in employees:
|
% for i in range(0, len(employees)):
|
||||||
<option value="{{employee[0]}}">{{employee[1][0]}}</option>
|
<option value="{{i}}">{{employees[i][0]}}</option>
|
||||||
% end
|
% end
|
||||||
</select>
|
</select>
|
||||||
<button type="submit">Einloggen</button>
|
<button type="submit">Einloggen</button>
|
||||||
|
|
Loading…
Reference in a new issue