modified: app.py
modified: templates/playlists.html
This commit is contained in:
31
app.py
31
app.py
@@ -117,13 +117,23 @@ def callback():
|
|||||||
user = sp.current_user()
|
user = sp.current_user()
|
||||||
session["user"] = user
|
session["user"] = user
|
||||||
|
|
||||||
return redirect("/playlists")
|
# Setze ein 30-Tage-Cookie mit Userdaten (ohne Token!)
|
||||||
|
resp = redirect("/playlists")
|
||||||
|
user_cookie = json.dumps({
|
||||||
|
"id": user.get("id"),
|
||||||
|
"display_name": user.get("display_name"),
|
||||||
|
"email": user.get("email"),
|
||||||
|
"images": user.get("images"),
|
||||||
|
})
|
||||||
|
resp.set_cookie("quizify_user", user_cookie, max_age=60*60*24*30, httponly=True, samesite="Lax")
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.route("/playlists")
|
@app.route("/playlists")
|
||||||
def playlists():
|
def playlists():
|
||||||
sp = get_spotify_client()
|
sp = get_spotify_client()
|
||||||
playlists = sp.current_user_playlists()["items"]
|
playlists = sp.current_user_playlists()["items"]
|
||||||
return render_template("playlists.html", playlists=playlists, translations=get_translations())
|
user = get_user_from_cookie()
|
||||||
|
return render_template("playlists.html", playlists=playlists, translations=get_translations(), user=user)
|
||||||
|
|
||||||
@app.route("/quiz/<playlist_id>")
|
@app.route("/quiz/<playlist_id>")
|
||||||
def quiz(playlist_id):
|
def quiz(playlist_id):
|
||||||
@@ -169,6 +179,7 @@ def quiz(playlist_id):
|
|||||||
}
|
}
|
||||||
all_tracks.append(track_info)
|
all_tracks.append(track_info)
|
||||||
|
|
||||||
|
user = get_user_from_cookie()
|
||||||
return render_template(
|
return render_template(
|
||||||
"quiz.html",
|
"quiz.html",
|
||||||
track=track,
|
track=track,
|
||||||
@@ -180,7 +191,8 @@ def quiz(playlist_id):
|
|||||||
total_questions=len(tracks),
|
total_questions=len(tracks),
|
||||||
score=score,
|
score=score,
|
||||||
answered=answered,
|
answered=answered,
|
||||||
translations=get_translations()
|
translations=get_translations(),
|
||||||
|
user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route("/search_track", methods=["POST"])
|
@app.route("/search_track", methods=["POST"])
|
||||||
@@ -282,7 +294,9 @@ def toggle_playback():
|
|||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
session.clear()
|
session.clear()
|
||||||
return redirect(url_for('home'))
|
resp = redirect(url_for('home'))
|
||||||
|
resp.set_cookie("quizify_user", "", expires=0)
|
||||||
|
return resp
|
||||||
|
|
||||||
@app.route("/reset_quiz/<playlist_id>")
|
@app.route("/reset_quiz/<playlist_id>")
|
||||||
def reset_quiz(playlist_id):
|
def reset_quiz(playlist_id):
|
||||||
@@ -318,5 +332,14 @@ def guest_join(token):
|
|||||||
resp.set_cookie("guest_token", token, max_age=60*60) # 1 Stunde gültig
|
resp.set_cookie("guest_token", token, max_age=60*60) # 1 Stunde gültig
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
def get_user_from_cookie():
|
||||||
|
user_cookie = request.cookies.get("quizify_user")
|
||||||
|
if user_cookie:
|
||||||
|
try:
|
||||||
|
return json.loads(user_cookie)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -143,6 +143,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if user %}
|
||||||
|
<div style="text-align:right;">
|
||||||
|
<img src="{{ user.images[0].url if user.images and user.images[0] }}" style="width:32px;border-radius:50%;vertical-align:middle;">
|
||||||
|
<span>{{ user.display_name }}</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function openInvitePopup() {
|
function openInvitePopup() {
|
||||||
document.getElementById('invitePopup').style.display = 'flex';
|
document.getElementById('invitePopup').style.display = 'flex';
|
||||||
|
|||||||
Reference in New Issue
Block a user