From a22cb644b90765f0eca7aa3859b349001d6160c8 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:36:27 +0200 Subject: [PATCH] modified: app.py --- app.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 39846c5..8607f67 100644 --- a/app.py +++ b/app.py @@ -477,7 +477,7 @@ def user_giveaways(): connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank cursor = connection.cursor(dictionary=True) - # Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist + # Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist (winner_dc_id) cursor.execute(""" SELECT * FROM giveaways WHERE winner_dc_id = %s AND aktiv = TRUE """, (user_id,)) @@ -486,12 +486,19 @@ def user_giveaways(): cursor.close() connection.close() - return render_template("user_giveaways.html", user_info=user_info, giveaways=won_giveaways) + if won_giveaways: + return render_template("user_giveaways.html", user_info=user_info, giveaways=won_giveaways) + else: + flash("You have not won any giveaways.", "info") + return render_template("user_giveaways.html", user_info=user_info, giveaways=[]) return redirect(url_for("login")) -@app.route("/user/giveaway/redeem/", methods=["POST"]) -def redeem_giveaway(giveaway_id): + + return redirect(url_for("login")) + +@app.route("/user/giveaway/redeem/", methods=["POST"]) +def redeem_giveaway(giveaway_uuid): """Erlaubt dem Benutzer, seinen Giveaway-Preis abzuholen.""" if "discord_user" in session: user_info = session["discord_user"] @@ -500,14 +507,17 @@ def redeem_giveaway(giveaway_id): connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank cursor = connection.cursor(dictionary=True) - # Überprüfe, ob der eingeloggte Benutzer der Gewinner ist - cursor.execute("SELECT * FROM giveaways WHERE id = %s AND winner_dc_id = %s AND aktiv = TRUE", (giveaway_id, user_id)) + # Überprüfe, ob der eingeloggte Benutzer der Gewinner ist und die UUID übereinstimmt + cursor.execute(""" + SELECT * FROM giveaways WHERE uuid = %s AND winner_dc_id = %s AND aktiv = TRUE + """, (giveaway_uuid, user_id)) giveaway = cursor.fetchone() if giveaway: # Setze das Giveaway auf inaktiv, damit es nicht erneut eingelöst werden kann - cursor.execute("UPDATE giveaways SET aktiv = FALSE WHERE id = %s", (giveaway_id,)) + cursor.execute("UPDATE giveaways SET aktiv = FALSE WHERE uuid = %s", (giveaway_uuid,)) connection.commit() + flash("You have successfully redeemed your prize!", "success") else: flash("You are not the winner of this giveaway or the giveaway is no longer active.", "danger") @@ -519,6 +529,5 @@ def redeem_giveaway(giveaway_id): return redirect(url_for("login")) - if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)