Add delete prepaid and show prepaid users

Shows only prepaid users which postpaid_id equals logged in id
an deletes only users whose money equals 0. Additionally a lot
of style improvements in base.html and new favicons which
actually load in.
This commit is contained in:
2025-05-19 17:49:29 +02:00
parent cd2b7ae14c
commit eec8f54eab
7 changed files with 253 additions and 542 deletions

View File

@@ -320,3 +320,12 @@ def set_prepaid_user_money(user_id: int, money: int, postpaid_user_id: int):
raise HTTPException(status_code=404, detail="User not found")
connection.commit()
return result.rowcount
def del_user_prepaid(user_id: int):
t = text("DELETE FROM users_prepaid WHERE id = :id")
with engine.connect() as connection:
result = connection.execute(t, {"id": user_id})
if result.rowcount == 0:
raise HTTPException(status_code=404, detail="User not found")
connection.commit()
return result.rowcount

91
main.py
View File

@@ -19,6 +19,7 @@ from db.models import create_prepaid_user
from db.models import drink_prepaid_user
from db.models import toggle_activate_prepaid_user
from db.models import set_prepaid_user_money
from db.models import del_user_prepaid
from auth import oidc
@@ -37,6 +38,8 @@ templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
def home(request: Request):
# Check if user is logged in and has a valid session
user_db_id = request.session.get("user_db_id")
user_authentik = request.session.get("user_authentik")
if not user_db_id or not user_authentik:
@@ -45,9 +48,9 @@ def home(request: Request):
user_db_id = request.session.get("user_db_id")
user_authentik = request.session.get("user_authentik")
if not user_db_id or not user_authentik:
raise HTTPException(status_code=404, detail="User nicht gefunden")
print(f"Current user: {user_authentik}")
print(f"Current user db id: {user_db_id}")
raise HTTPException(status_code=404, detail="User not found")
# if user is Admin, load all postpaid users
users = None
db_users_prepaid = None
if ADMIN_GROUP in user_authentik["groups"]:
@@ -60,6 +63,9 @@ def home(request: Request):
user_db = get_postpaid_user(row[0])
if user_db:
users.append(user_db)
# if user is in Fachschaft, load all prepaid users
prepaid_users_from_curr_user = []
if FS_GROUP in user_authentik["groups"]:
with engine.connect() as conn:
t = text("SELECT id FROM users_prepaid")
@@ -70,15 +76,23 @@ def home(request: Request):
prepaid_user = get_prepaid_user(row[0])
if prepaid_user:
db_users_prepaid.append(prepaid_user)
# additionally load all prepaid users from the current user
t = text("SELECT id, username, user_key, money, last_drink FROM users_prepaid WHERE postpaid_user_id = :user_db_id")
result = conn.execute(t, {"user_db_id": user_db_id}).fetchall()
if result:
prepaid_users_from_curr_user = []
for row in result:
prepaid_user = get_prepaid_user(row[0])
if prepaid_user:
prepaid_users_from_curr_user.append(prepaid_user)
# load current user from database
try:
if user_authentik["prepaid"]:
print("Prepaid user")
db_user = get_prepaid_user(user_db_id)
else:
print("Postpaid user")
db_user = get_postpaid_user(user_db_id)
except KeyError:
print("Postpaid user")
db_user = get_postpaid_user(user_db_id)
return templates.TemplateResponse("index.html", {
"request": request,
@@ -86,7 +100,8 @@ def home(request: Request):
"users": users,
"user_db_id": user_db_id,
"db_user": db_user,
"db_users_prepaid": db_users_prepaid})
"db_users_prepaid": db_users_prepaid,
"prepaid_users_from_curr_user": prepaid_users_from_curr_user,})
@app.get("/login", response_class=HTMLResponse)
def login_form(request: Request):
@@ -120,13 +135,8 @@ def set_money_postpaid(request: Request, username = Form(...), money: float = Fo
if not user_authentik or ADMIN_GROUP not in user_authentik["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
with engine.connect() as conn:
t = text("SELECT id FROM users_postpaid WHERE username = :username")
result = conn.execute(t, {"username": username}).fetchone()
if result:
requested_user_id = result[0]
else:
raise HTTPException(status_code=404, detail="User nicht gefunden")
user = get_postpaid_user_by_username(username)
requested_user_id = user["id"]
set_postpaid_user_money(requested_user_id, money*100)
return RedirectResponse(url="/", status_code=303)
@@ -150,11 +160,11 @@ def drink(request: Request):
user_authentik = request.session.get("user_authentik")
if not user_authentik or FS_GROUP not in user_authentik["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
user_db_id = request.session.get("user_db_id")
if not user_db_id:
raise HTTPException(status_code=404, detail="User nicht gefunden")
raise HTTPException(status_code=404, detail="User not found")
drink_postpaid_user(user_db_id)
return RedirectResponse(url="/", status_code=303)
@@ -163,18 +173,18 @@ def drink(request: Request):
def payup(request: Request, username: str = Form(...), money: float = Form(...)):
user_auth = request.session.get("user_authentik")
if not user_auth or ADMIN_GROUP not in user_auth["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
user_db_id = get_postpaid_user_by_username(username)["id"]
if not user_db_id:
raise HTTPException(status_code=404, detail="User nicht gefunden")
raise HTTPException(status_code=404, detail="User not found")
curr_user_money = get_postpaid_user(user_db_id)["money"]
set_postpaid_user_money(user_db_id, curr_user_money + money*100)
current_user_db_id = request.session.get("user_db_id")
if not current_user_db_id:
raise HTTPException(status_code=404, detail="Aktueller User nicht gefunden")
raise HTTPException(status_code=404, detail="Current user not found")
current_user_money = get_postpaid_user(current_user_db_id)["money"]
set_postpaid_user_money(current_user_db_id, current_user_money - money*100)
return RedirectResponse(url="/", status_code=303)
@@ -183,11 +193,11 @@ def payup(request: Request, username: str = Form(...), money: float = Form(...))
def toggle_activated_user_postpaid(request: Request, username: str = Form(...)):
user_auth = request.session.get("user_authentik")
if not user_auth or ADMIN_GROUP not in user_auth["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
user_db_id = get_postpaid_user_by_username(username)["id"]
if not user_db_id:
raise HTTPException(status_code=404, detail="User nicht gefunden")
raise HTTPException(status_code=404, detail="User not found")
toggle_activate_postpaid_user(user_db_id)
@@ -199,11 +209,11 @@ def add_prepaid_user(request: Request, username: str = Form(...), start_money: f
active_user_auth = request.session.get("user_authentik")
active_user_db_id = request.session.get("user_db_id")
if not active_user_auth or ADMIN_GROUP not in active_user_auth["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
if not active_user_db_id:
raise HTTPException(status_code=404, detail="Aktueller User nicht gefunden")
raise HTTPException(status_code=404, detail="Current user not found")
if not username:
raise HTTPException(status_code=400, detail="Username ist leer")
raise HTTPException(status_code=400, detail="Username is empty")
user_exists = False
try:
@@ -215,7 +225,7 @@ def add_prepaid_user(request: Request, username: str = Form(...), start_money: f
pass
if user_exists:
raise HTTPException(status_code=400, detail="User existiert bereits")
raise HTTPException(status_code=400, detail="User already exists")
create_prepaid_user(username, active_user_db_id, int(start_money*100))
@@ -228,12 +238,12 @@ def add_prepaid_user(request: Request, username: str = Form(...), start_money: f
def drink_prepaid(request: Request):
user_db_id = request.session.get("user_db_id")
if not user_db_id:
raise HTTPException(status_code=404, detail="User nicht gefunden")
raise HTTPException(status_code=404, detail="User not found")
user_authentik = request.session.get("user_authentik")
if not user_authentik:
raise HTTPException(status_code=404, detail="User nicht gefunden")
raise HTTPException(status_code=404, detail="User not found")
if not user_authentik["prepaid"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
drink_prepaid_user(user_db_id)
return RedirectResponse(url="/", status_code=303)
@@ -242,11 +252,11 @@ def drink_prepaid(request: Request):
def toggle_activated_user_prepaid(request: Request, username: str = Form(...)):
user_auth = request.session.get("user_authentik")
if not user_auth or ADMIN_GROUP not in user_auth["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
user_db_id = get_prepaid_user_by_username(username)["id"]
if not user_db_id:
raise HTTPException(status_code=404, detail="User nicht gefunden")
raise HTTPException(status_code=404, detail="User not found")
toggle_activate_prepaid_user(user_db_id)
@@ -256,7 +266,7 @@ def toggle_activated_user_prepaid(request: Request, username: str = Form(...)):
def add_money_prepaid_user(request: Request, username: str = Form(...), money: float = Form(...)):
curr_user_auth = request.session.get("user_authentik")
if not curr_user_auth or FS_GROUP not in curr_user_auth["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
raise HTTPException(status_code=403, detail="Not allowed")
curr_user_db_id = request.session.get("user_db_id")
if not curr_user_db_id:
raise HTTPException(status_code=404, detail="Logged In User not found")
@@ -273,5 +283,24 @@ def add_money_prepaid_user(request: Request, username: str = Form(...), money: f
return RedirectResponse(url="/", status_code=303)
@app.post("/del_prepaid_user")
def delete_prepaid_user(request: Request, username: str = Form(...)):
# check if user is in ADMIN_GROUP
user_auth = request.session.get("user_authentik")
if not user_auth or ADMIN_GROUP not in user_auth["groups"]:
raise HTTPException(status_code=403, detail="Nicht erlaubt")
user_to_del = get_prepaid_user_by_username(username)
if not user_to_del["id"]:
raise HTTPException(status_code=404, detail="User not found")
if user_to_del["money"] > 0:
raise HTTPException(status_code=400, detail="User still has money")
del_user_prepaid(user_to_del["id"])
return RedirectResponse(url="/", status_code=303)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

BIN
static/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 B

BIN
static/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,524 +1,197 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<title>{% block title %}Getränkeliste{% endblock %}</title>
<link rel="stylesheet" href="/static/style.css" />
</head>
<body>
<header>
<img
src="/Users/moritz/Documents/Uni/Fachschaft/GetraenkelisteWebsite/fachschaftslogo.png"
alt="Logo"
style="height: 50px; vertical-align: middle"
/>
<h1>Getränkeliste</h1>
{% if user %}
<head>
<meta charset="UTF-8" />
<title>{% block title %}Getränkeliste{% endblock %}</title>
<link rel="stylesheet" href="/static/style.css" />
<link rel="icon" type="image/png" href="/static/favicon.ico" />
</head>
<body>
<header>
<img src="/static/fachschaftslogo.png" alt="Logo" style="height: 50px; vertical-align: middle" />
<h1>Getränkeliste</h1>
{% if user %}
<p>
Angemeldet als {{ user.preferred_username }}{% if 'Fachschaft Admins' in user.groups %} (Admin){% endif %}
<a href="/logout">Logout</a>
</p>
{% endif %}
</header>
<main>
{% block content %}{% endblock %} {% if user %} {% if 'Fachschaft'
in user.groups %}
<p>Du bist Teil der Fachschaft Informatik.</p>
<p>Füge Nutzer zur Prepaid Liste hinzu:</p>
<form
method="post"
action="/add_prepaid_user"
style="
display: flex;
gap: 1em;
align-items: center;
margin-bottom: 1em;
background: var(--hellgrau);
padding: 1em;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
max-width: 600px;
"
>
<label
for="username"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Username:</label
>
<input
id="username"
type="text"
name="username"
placeholder="Username"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
width: 100%;
"
/>
<label
for="start_money"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Start Money (€):</label
>
<input
id="start_money"
type="number"
name="start_money"
placeholder="Start Money"
step="0.01"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
width: 100px;
"
/>
<button
type="submit"
style="
padding: 0.5em 1em;
background: rgb(0, 97, 143);
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
"
>
Add User
</button>
</form>
<p>Füge bestehendem Prepaid-User Geld hinzu:</p>
{% if db_users_prepaid %}
<form
method="post"
action="/add_money_prepaid_user"
style="
display: flex;
gap: 1em;
align-items: center;
margin-bottom: 1em;
background: var(--hellgrau);
padding: 1em;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
max-width: 600px;
"
>
<label
for="addmoney-username"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Username:</label
>
<select
id="addmoney-username"
name="username"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
"
>
{% for db_user in db_users_prepaid %}
<option value="{{ db_user.username }}">
{{ db_user.username }}
</option>
{% endfor %}
</select>
<label
for="addmoney-money"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Amount (€):</label
>
<input
id="addmoney-money"
type="number"
name="money"
placeholder="Money"
step="0.01"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
width: 100px;
"
/>
<button
type="submit"
style="
padding: 0.5em 1em;
background: rgb(0, 97, 143);
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
"
>
Add Money
</button>
{% endif %}
</header>
<main>
{% block content %}{% endblock %}
{% if user %}
{% if 'Fachschaft' in user.groups %}
<p>Du bist Teil der Fachschaft Informatik.</p>
{% if prepaid_users_from_curr_user %}
<p>Liste deiner Prepaid-User:</p>
<table>
<thead>
<tr>
<th style="padding: 0.5em 1em">ID</th>
<th style="padding: 0.5em 1em">Username</th>
<th style="padding: 0.5em 1em">Key</th>
<th style="padding: 0.5em 1em">Postpaid_User ID</th>
<th style="padding: 0.5em 1em">Money (€)</th>
<th style="padding: 0.5em 1em">Activated</th>
<th style="padding: 0.5em 1em">last drink</th>
</tr>
</thead>
<tbody>
{% for prepaid_user_i in prepaid_users_from_curr_user %}
<tr{% if prepaid_user_i.money <= 0 %} style="background-color: rgba(179, 6, 44, 0.5)"{% endif %}>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.id }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.username }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.user_key }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.postpaid_user_id }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.money / 100 }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.activated }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.last_drink }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<p>Füge Nutzer zur Prepaid Liste hinzu:</p>
<form method="post" action="/add_prepaid_user" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<input id="username" type="text" name="username" placeholder="Username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px; width: 100%;" />
<label for="start_money" style="margin: 0 0.5em 0 0; font-weight: bold">Start Money (€):</label>
<input id="start_money" type="number" name="start_money" placeholder="Start Money" step="0.01" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px; width: 100px;" />
<button type="submit" style="padding: 0.5em 1em; background: rgb(0, 97, 143); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Add User</button>
</form>
{% else %}
<p>Es sind keine Prepaid-User vorhanden.</p>
{% endif %}
<p>Füge bestehendem Prepaid-User Geld hinzu:</p>
{% if db_users_prepaid %}
<form method="post" action="/add_money_prepaid_user" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="addmoney-username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<select id="addmoney-username" name="username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px;">
{% for db_user in db_users_prepaid %}
<option value="{{ db_user.username }}">{{ db_user.username }}</option>
{% endfor %}
</select>
<label for="addmoney-money" style="margin: 0 0.5em 0 0; font-weight: bold">Amount (€):</label>
<input id="addmoney-money" type="number" name="money" placeholder="Money" step="0.01" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px; width: 100px;" />
<button type="submit" style="padding: 0.5em 1em; background: rgb(0, 97, 143); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Add Money</button>
</form>
{% else %}
<p>Es sind keine Prepaid-User vorhanden.</p>
{% endif %}
{% endif %}
{% if 'Fachschaft Admins' in user.groups %}
<h2>Admin Interface</h2>
<p>Ausgleichszahlung:</p>
<p>
Der eingegebene Betrag wird vom aktuell eingeloggten Nutzer
abgezogen und dem eingetragenem Nutzer gutgeschrieben.
</p>
<form
method="post"
action="/payup"
style="
display: flex;
gap: 1em;
align-items: center;
margin-bottom: 1em;
background: var(--hellgrau);
padding: 1em;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
max-width: 600px;
"
>
<label
for="payup-username"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Username:</label
>
<select
id="payup-username"
name="username"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
"
>
{% for db_user in users %}
<option value="{{ db_user.username }}">
{{ db_user.username }}
</option>
{% endfor %}
</select>
<label
for="payup-money"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Amount (€):</label
>
<input
id="payup-money"
type="number"
name="money"
placeholder="Money"
step="0.01"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
width: 100px;
"
/>
<button
type="submit"
style="
padding: 0.5em 1em;
background: rgb(0, 97, 143);
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
"
>
Pay Up
</button>
</form>
<h3>Postpaid Liste</h3>
<p>Users in postpaid database:</p>
<table>
<thead>
<tr>
<th style="padding: 0.5em 1em">ID</th>
<th style="padding: 0.5em 1em">Username</th>
<th style="padding: 0.5em 1em">Money (€)</th>
<th style="padding: 0.5em 1em">Activated</th>
<th style="padding: 0.5em 1em">last drink</th>
</tr>
</thead>
<tbody>
{% for db_user_i in users %}
<tr
{%
if
db_user_i.money
<=-5000
%}
style="background-color: rgba(179, 6, 44, 0.5)"
{%
endif
%}
>
<td style="padding: 0.5em 1em">
{{ db_user_i.id }}
</td>
<td style="padding: 0.5em 1em">
{{ db_user_i.username }}
</td>
<td style="padding: 0.5em 1em">
{{ db_user_i.money / 100 }}
</td>
<td style="padding: 0.5em 1em">
{{ db_user_i.activated }}
</td>
<td style="padding: 0.5em 1em">
{{ db_user_i.last_drink }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>(De-)Activate User</p>
<form
method="post"
action="/toggle_activated_user_postpaid"
style="
display: flex;
gap: 1em;
align-items: center;
margin-bottom: 1em;
background: var(--hellgrau);
padding: 1em;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
max-width: 600px;
"
>
<label
for="activate-username"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Username:</label
>
<select
id="activate-username"
name="username"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
"
>
{% for db_user in users %}
<option value="{{ db_user.username }}">
{{ db_user.username }}
</option>
{% endfor %}
</select>
<button
type="submit"
style="
padding: 0.5em 1em;
background: rgb(0, 97, 143);
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
"
>
Toggle Activation
</button>
</form>
<p>Set user money:</p>
<form
method="post"
action="/set_money_postpaid"
style="
display: flex;
gap: 1em;
align-items: center;
margin-bottom: 1em;
background: var(--hellgrau);
padding: 1em;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
max-width: 600px;
"
>
<label
for="setmoney-username"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Username:</label
>
<select
id="setmoney-username"
name="username"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
"
>
{% for db_user in users %}
<option value="{{ db_user.username }}">
{{ db_user.username }}
</option>
{% endfor %}
</select>
<label
for="setmoney-money"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Amount (€):</label
>
<input
id="setmoney-money"
type="number"
name="money"
placeholder="Money"
step="0.01"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
width: 100px;
"
/>
<button
type="submit"
style="
padding: 0.5em 1em;
background: rgb(0, 97, 143);
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
"
>
Set Money
</button>
</form>
<h3>Prepaid Liste</h3>
<p>Users in prepaid database:</p>
{% if db_users_prepaid %}
<table>
<thread>
<tr>
<th style="padding: 0.5em 1em">ID</th>
<th style="padding: 0.5em 1em">Username</th>
<th style="padding: 0.5em 1em">Key</th>
<th style="padding: 0.5em 1em">Postpaid_User ID</th>
<th style="padding: 0.5em 1em">Money (€)</th>
<th style="padding: 0.5em 1em">Activated</th>
<th style="padding: 0.5em 1em">last drink</th>
</tr>
</thread>
<tbody>
{% for prepaid_user_i in db_users_prepaid %}
<tr
{%
if
prepaid_user_i.money
<=0
%}
style="background-color: rgba(179, 6, 44, 0.5)"
{%
endif
%}
>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.id }}
</td>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.username }}
</td>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.user_key }}
</td>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.postpaid_user_id }}
</td>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.money / 100 }}
</td>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.activated }}
</td>
<td style="padding: 0.5em 1em">
{{ prepaid_user_i.last_drink }}
</td>
</tr>
<h2>Admin Interface</h2>
<p>Ausgleichszahlung:</p>
<p>Der eingegebene Betrag wird vom aktuell eingeloggten Nutzer abgezogen und dem eingetragenem Nutzer gutgeschrieben.</p>
<form method="post" action="/payup" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="payup-username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<select id="payup-username" name="username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px;">
{% for db_user in users %}
<option value="{{ db_user.username }}">{{ db_user.username }}</option>
{% endfor %}
</tbody>
</table>
<p>(De-)Activate User</p>
<form
method="post"
action="/toggle_activated_user_prepaid"
style="
display: flex;
gap: 1em;
align-items: center;
margin-bottom: 1em;
background: var(--hellgrau);
padding: 1em;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
max-width: 600px;
"
>
<label
for="activate-username"
style="margin: 0 0.5em 0 0; font-weight: bold"
>Username:</label
>
<select
id="activate-username"
name="username"
required
style="
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
"
>
{% for db_user in db_users_prepaid %}
<option value="{{ db_user.username }}">
{{ db_user.username }}
</option>
{% endfor %}
</select>
<button
type="submit"
style="
padding: 0.5em 1em;
background: rgb(0, 97, 143);
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
"
>
Toggle Activation
</button>
</form>
{% else %}
</select>
<label for="payup-money" style="margin: 0 0.5em 0 0; font-weight: bold">Amount (€):</label>
<input id="payup-money" type="number" name="money" placeholder="Money" step="0.01" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px; width: 100px;" />
<button type="submit" style="padding: 0.5em 1em; background: rgb(0, 97, 143); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Pay Up</button>
</form>
<h3>Postpaid Liste</h3>
<p>Users in postpaid database:</p>
<table>
<thead>
<tr>
<th style="padding: 0.5em 1em">ID</th>
<th style="padding: 0.5em 1em">Username</th>
<th style="padding: 0.5em 1em">Money (€)</th>
<th style="padding: 0.5em 1em">Activated</th>
<th style="padding: 0.5em 1em">last drink</th>
</tr>
</thead>
<tbody>
{% for db_user_i in users %}
<tr{% if db_user_i.money <= -5000 %} style="background-color: rgba(179, 6, 44, 0.5)"{% endif %}>
<td style="padding: 0.5em 1em">{{ db_user_i.id }}</td>
<td style="padding: 0.5em 1em">{{ db_user_i.username }}</td>
<td style="padding: 0.5em 1em">{{ db_user_i.money / 100 }}</td>
<td style="padding: 0.5em 1em">{{ db_user_i.activated }}</td>
<td style="padding: 0.5em 1em">{{ db_user_i.last_drink }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>(De-)Activate User</p>
<form method="post" action="/toggle_activated_user_postpaid" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="activate-username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<select id="activate-username" name="username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px;">
{% for db_user in users %}
<option value="{{ db_user.username }}">{{ db_user.username }}</option>
{% endfor %}
</select>
<button type="submit" style="padding: 0.5em 1em; background: rgb(0, 97, 143); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Toggle Activation</button>
</form>
<p>Set user money:</p>
<form method="post" action="/set_money_postpaid" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="setmoney-username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<select id="setmoney-username" name="username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px;">
{% for db_user in users %}
<option value="{{ db_user.username }}">{{ db_user.username }}</option>
{% endfor %}
</select>
<label for="setmoney-money" style="margin: 0 0.5em 0 0; font-weight: bold">Amount (€):</label>
<input id="setmoney-money" type="number" name="money" placeholder="Money" step="0.01" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px; width: 100px;" />
<button type="submit" style="padding: 0.5em 1em; background: rgb(0, 97, 143); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Set Money</button>
</form>
<h3>Prepaid Liste</h3>
<p>Users in prepaid database:</p>
{% if db_users_prepaid %}
<table>
<thead>
<tr>
<th style="padding: 0.5em 1em">ID</th>
<th style="padding: 0.5em 1em">Username</th>
<th style="padding: 0.5em 1em">Key</th>
<th style="padding: 0.5em 1em">Postpaid_User ID</th>
<th style="padding: 0.5em 1em">Money (€)</th>
<th style="padding: 0.5em 1em">Activated</th>
<th style="padding: 0.5em 1em">last drink</th>
</tr>
</thead>
<tbody>
{% for prepaid_user_i in db_users_prepaid %}
<tr{% if prepaid_user_i.money <= 0 %} style="background-color: rgba(179, 6, 44, 0.5)"{% endif %}>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.id }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.username }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.user_key }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.postpaid_user_id }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.money / 100 }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.activated }}</td>
<td style="padding: 0.5em 1em">{{ prepaid_user_i.last_drink }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>(De-)Activate User</p>
<form method="post" action="/toggle_activated_user_prepaid" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="activate-username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<select id="activate-username" name="username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px;">
{% for db_user in db_users_prepaid %}
<option value="{{ db_user.username }}">{{ db_user.username }}</option>
{% endfor %}
</select>
<button type="submit" style="padding: 0.5em 1em; background: rgb(0, 97, 143); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Toggle Activation</button>
</form>
<p>Delete User</p>
<form method="post" action="/del_prepaid_user" style="display: flex; gap: 1em; align-items: center; margin-bottom: 1em; background: var(--hellgrau); padding: 1em; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); max-width: 600px;">
<label for="del-username" style="margin: 0 0.5em 0 0; font-weight: bold">Username:</label>
<select id="del-username" name="username" required style="padding: 0.5em; border: 1px solid #ccc; border-radius: 4px;">
{% for db_user in db_users_prepaid %}
<option value="{{ db_user.username }}">{{ db_user.username }}</option>
{% endfor %}
</select>
<button type="submit" style="padding: 0.5em 1em; background: rgb(179, 6, 44); color: #fff; border: none; border-radius: 4px; cursor: pointer;">Delete User</button>
{% else %}
<tr>
<td colspan="7" style="text-align: center">
No users in prepaid database
</td>
<td colspan="7" style="text-align: center">No users in prepaid database</td>
</tr>
{% endif %}
{% endif %} {% endif %}
</main>
</body>
{% endif %}
{% endif %}
{% endif %}
</main>
</body>
</html>