modified: app.py
modified: templates/playlists.html
This commit is contained in:
23
app.py
23
app.py
@@ -11,6 +11,8 @@ from difflib import SequenceMatcher
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
import secrets
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = os.getenv("SECRET_KEY")
|
app.secret_key = os.getenv("SECRET_KEY")
|
||||||
@@ -295,5 +297,26 @@ def reset_quiz(playlist_id):
|
|||||||
def gamemodes(playlist_id):
|
def gamemodes(playlist_id):
|
||||||
return render_template("gamemodes.html", playlist_id=playlist_id, translations=get_translations())
|
return render_template("gamemodes.html", playlist_id=playlist_id, translations=get_translations())
|
||||||
|
|
||||||
|
invites = {} # {token: expiry_datetime}
|
||||||
|
|
||||||
|
@app.route("/invite")
|
||||||
|
def invite():
|
||||||
|
duration = int(request.args.get("duration", 60)) # Minuten
|
||||||
|
token = secrets.token_urlsafe(16)
|
||||||
|
expires = datetime.utcnow() + timedelta(minutes=duration)
|
||||||
|
invites[token] = expires
|
||||||
|
invite_link = url_for('guest_join', token=token, _external=True)
|
||||||
|
return render_template("invite.html", invite_link=invite_link, expires=expires)
|
||||||
|
|
||||||
|
@app.route("/invite/<token>")
|
||||||
|
def guest_join(token):
|
||||||
|
expires = invites.get(token)
|
||||||
|
if not expires or expires < datetime.utcnow():
|
||||||
|
return "Invite link expired or invalid.", 403
|
||||||
|
# Setze ein Cookie, damit der Gast als eingeladener User erkannt wird (optional)
|
||||||
|
resp = redirect(url_for('login'))
|
||||||
|
resp.set_cookie("guest_token", token, max_age=60*60) # 1 Stunde gültig
|
||||||
|
return resp
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
|
|||||||
@@ -51,6 +51,22 @@
|
|||||||
background-color: #1ed760;
|
background-color: #1ed760;
|
||||||
transform: scale(1.04);
|
transform: scale(1.04);
|
||||||
}
|
}
|
||||||
|
.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 10px 20px;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 5px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: bold;
|
||||||
|
transition: background 0.2s, transform 0.2s;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
.btn:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -64,6 +80,7 @@
|
|||||||
<li><a class="playlist-link" href="/gamemodes/{{ pl.id }}">{{ pl.name }}</a></li>
|
<li><a class="playlist-link" href="/gamemodes/{{ pl.id }}">{{ pl.name }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
<a href="{{ url_for('invite') }}?duration=60" class="btn">Gast einladen (1h-Link)</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user