Add darkmode and check for overdraft
This commit is contained in:
BIN
fachschaftslogo.png
Normal file
BIN
fachschaftslogo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
23
main.py
23
main.py
@@ -14,6 +14,8 @@ import uvicorn
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
ADMIN_GROUP = "Fachschaft Admins"
|
||||
|
||||
app = FastAPI()
|
||||
app.add_middleware(SessionMiddleware, secret_key="my_secret_key")
|
||||
app.include_router(oidc.router)
|
||||
@@ -32,7 +34,7 @@ def home(request: Request, user: User = Depends(get_current_user), db: Session =
|
||||
if not db_user:
|
||||
raise HTTPException(status_code=404, detail="User nicht gefunden")
|
||||
users = None
|
||||
if "Fachschaft Admins" in user["groups"]:
|
||||
if ADMIN_GROUP in user["groups"]:
|
||||
users = db.query(User).all()
|
||||
return templates.TemplateResponse("index.html", {"request": request, "user": user, "users": users, "db_user": db_user})
|
||||
|
||||
@@ -42,7 +44,7 @@ def login_form(request: Request):
|
||||
|
||||
@app.post("/set_money")
|
||||
def set_money(request: Request, username: str = Form(...), money: float = Form(...), db: Session = Depends(get_db), user: User = Depends(get_current_user)):
|
||||
if not user or "Fachschaft Admins" not in user["groups"]:
|
||||
if not user or ADMIN_GROUP not in user["groups"]:
|
||||
raise HTTPException(status_code=403, detail="Nicht erlaubt")
|
||||
db_user = db.query(User).filter_by(username=username).first()
|
||||
if not db_user:
|
||||
@@ -53,7 +55,7 @@ def set_money(request: Request, username: str = Form(...), money: float = Form(.
|
||||
|
||||
@app.post("/drink")
|
||||
def drink(request: Request, db: Session = Depends(get_db), user: User = Depends(get_current_user)):
|
||||
if not user or "Fachschaft" not in user["groups"]:
|
||||
if not user or ADMIN_GROUP not in user["groups"]:
|
||||
raise HTTPException(status_code=403, detail="Nicht erlaubt")
|
||||
db_user = db.query(User).filter_by(username=user["preferred_username"]).first()
|
||||
if not db_user:
|
||||
@@ -62,5 +64,20 @@ def drink(request: Request, db: Session = Depends(get_db), user: User = Depends(
|
||||
db.commit()
|
||||
return RedirectResponse(url="/", status_code=303)
|
||||
|
||||
@app.post("/payup")
|
||||
def payup(request: Request, username: str = Form(...), money: float = Form(...), db: Session = Depends(get_db), user: User = Depends(get_current_user)):
|
||||
if not user or ADMIN_GROUP not in user["groups"]:
|
||||
raise HTTPException(status_code=403, detail="Nicht erlaubt")
|
||||
db_user = db.query(User).filter_by(username=username).first()
|
||||
if not db_user:
|
||||
raise HTTPException(status_code=404, detail="User nicht gefunden")
|
||||
db_user.money += money*100
|
||||
current_user = db.query(User).filter_by(username=user["preferred_username"]).first()
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=404, detail="Aktueller User nicht gefunden")
|
||||
current_user.money -= money*100
|
||||
db.commit()
|
||||
return RedirectResponse(url="/", status_code=303)
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
|
||||
@@ -9,3 +9,38 @@ header {
|
||||
padding: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
:root {
|
||||
--goetheblau: rgb(0, 97, 143);
|
||||
--purple: rgb(134, 0, 71);
|
||||
--emorot: rgb(179, 6, 44);
|
||||
--hellgrau: rgb(248, 246, 245);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--goetheblau: rgb(139, 207, 238);
|
||||
--purple: rgb(228, 96, 164);
|
||||
--emorot: rgb(179, 6, 44);
|
||||
--hellgrau: rgb(77, 75, 70); /* eig. Dunkelgrau */
|
||||
}
|
||||
body {
|
||||
background: #181a1b;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
header {
|
||||
background-color: #23272a;
|
||||
}
|
||||
main {
|
||||
background: #23272a;
|
||||
}
|
||||
table {
|
||||
background: #23272a;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
input, select, button {
|
||||
background: #23272a;
|
||||
color: #e0e0e0;
|
||||
border-color: #444;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{% block title %}Meine Seite{% endblock %}</title>
|
||||
<title>{% block title %}Getränkeliste{% endblock %}</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Meine Beispielseite</h1>
|
||||
<img src="/Users/moritz/Documents/Uni/Fachschaft/GetraenkelisteWebsite/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 %}
|
||||
@@ -20,20 +21,51 @@
|
||||
{% endif %}
|
||||
{% if 'Fachschaft Admins' in user.groups %}
|
||||
<h2>Admin Interface</h2>
|
||||
<p>Users in database:</p>
|
||||
<ul>
|
||||
{% for db_user in users %}
|
||||
<li>{{ db_user.username }} ({{ db_user.role }}) - {{ db_user.money / 100 }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<p>Set user money:</p>
|
||||
<form method="post" action="/set_money">
|
||||
<input type="text" name="username" placeholder="Username" required>
|
||||
<input type="number" name="money" placeholder="Money" step="0.01" required>
|
||||
<button type="submit">Set Money</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<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>
|
||||
<p>Users in database:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="padding: 0.5em 1em;">Username</th>
|
||||
<th style="padding: 0.5em 1em;">Role</th>
|
||||
<th style="padding: 0.5em 1em;">Money (€)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for db_user in users %}
|
||||
<tr{% if db_user.money <= -5000 %} style="background-color: rgba(179, 6, 44, 0.5);"{% endif %}>
|
||||
<td style="padding: 0.5em 1em;">{{ db_user.username }}</td>
|
||||
<td style="padding: 0.5em 1em;">{{ db_user.role }}</td>
|
||||
<td style="padding: 0.5em 1em;">{{ db_user.money / 100 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Set user money:</p>
|
||||
<form method="post" action="/set_money" 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>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</main>
|
||||
</body>
|
||||
|
||||
@@ -3,12 +3,37 @@
|
||||
{% block content %}
|
||||
<h2>Willkommen, {{ user.name }}!</h2>
|
||||
<p>Dies ist eine einfache geschützte Seite.</p>
|
||||
<h3>Aktueller Stand:</h3>
|
||||
<p>Du hast {{ db_user.money / 100 }} Euro.</p>
|
||||
<p><strong>Aktueller Kontostand:</strong></p>
|
||||
{% if db_user.money > -5000 %}
|
||||
<div style="text-align: center; font-size: 2em; color: var(--goetheblau); margin: 0.5em 0;">
|
||||
{{ db_user.money / 100 }} Euro
|
||||
</div>
|
||||
{% else %}
|
||||
<div style="text-align: center; font-size: 2em; color: var(--purple); margin: 0.5em 0; font-weight: bold;">
|
||||
{{ db_user.money / 100 }} Euro
|
||||
<br>
|
||||
<span style="color: var(--goetheblau); font-weight: normal; font-size: 1em;">
|
||||
Bitte begleiche deinen offenen Betrag!
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if 'Fachschaft' in user.groups %}
|
||||
<h3>Getränk abziehen</h3>
|
||||
<form method="post" action="/drink">
|
||||
<button type="submit">Abziehen</button>
|
||||
</form>
|
||||
{% if db_user.money > -5000 %}
|
||||
<div style="display: flex; justify-content: center;text-align: center;"></div>
|
||||
<form method="post" action="/drink">
|
||||
<button type="submit" style="background-color: rgb(165, 171, 82); color: rgb(255, 255, 255); font-size: 1.5em; padding: 0.75em 2em; border: none; border-radius: 8px; box-shadow: 0 4px 12px rgba(40,167,69,0.15); cursor: pointer; transition: background 0.2s;">
|
||||
Getränk abziehen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
<div style="display: flex; justify-content: center;text-align: center;"></div>
|
||||
<form method="post" action="/drink">
|
||||
<button type="submit" style="background-color: var(--emorot); color: rgb(255, 255, 255); font-size: 1.5em; padding: 0.75em 2em; border: none; border-radius: 8px; box-shadow: 0 4px 12px rgba(40,167,69,0.15); cursor: pointer; transition: background 0.2s;">
|
||||
Getränk abziehen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -4,9 +4,13 @@
|
||||
<h2>Login</h2>
|
||||
|
||||
<!-- SSO-Button -->
|
||||
<form method="get" action="/login/oidc">
|
||||
<button type="submit">🔐 Login with Authentik</button>
|
||||
</form>
|
||||
<div style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
|
||||
<form method="get" action="/login/oidc">
|
||||
<button type="submit" style="padding: 12px 28px; background-color: #1976d2; color: #fff; border: none; border-radius: 6px; font-size: 1.1em; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.08); transition: background 0.2s;">
|
||||
🔐 Login with Authentik
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- WebAuthn-Button -->
|
||||
<!-- <form method="get" action="/login/webauthn">
|
||||
|
||||
Reference in New Issue
Block a user