diff --git a/app.py b/app.py index 8607f67..99f55f9 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 (winner_dc_id) + # Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist cursor.execute(""" SELECT * FROM giveaways WHERE winner_dc_id = %s AND aktiv = TRUE """, (user_id,)) @@ -486,20 +486,13 @@ def user_giveaways(): cursor.close() connection.close() - 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 render_template("user_giveaways.html", user_info=user_info, giveaways=won_giveaways) return redirect(url_for("login")) - - return redirect(url_for("login")) - -@app.route("/user/giveaway/redeem/", methods=["POST"]) -def redeem_giveaway(giveaway_uuid): - """Erlaubt dem Benutzer, seinen Giveaway-Preis abzuholen.""" +@app.route("/user/giveaway/redeem/", methods=["GET"]) +def redeem_giveaway(uuid): + """Erlaubt dem Benutzer, den Giveaway-Code abzurufen.""" if "discord_user" in session: user_info = session["discord_user"] user_id = user_info["id"] @@ -507,18 +500,17 @@ def redeem_giveaway(giveaway_uuid): connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank cursor = connection.cursor(dictionary=True) - # Ü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)) + # Überprüfen, ob der eingeloggte Benutzer der Gewinner ist + cursor.execute("SELECT * FROM giveaways WHERE uuid = %s AND winner_dc_id = %s AND aktiv = TRUE", (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 uuid = %s", (giveaway_uuid,)) + cursor.execute("UPDATE giveaways SET aktiv = FALSE WHERE uuid = %s", (uuid,)) connection.commit() - flash("You have successfully redeemed your prize!", "success") + # Zeige den Key an + return render_template("redeem_giveaway.html", giveaway=giveaway, key=giveaway["game_key"]) else: flash("You are not the winner of this giveaway or the giveaway is no longer active.", "danger") diff --git a/templates/redeem_giveaway.html b/templates/redeem_giveaway.html new file mode 100644 index 0000000..7155127 --- /dev/null +++ b/templates/redeem_giveaway.html @@ -0,0 +1,28 @@ + + + + + + + Redeem Giveaway + + + + +
+

Giveaway Prize

+

Congratulations! You have won the giveaway for {{ giveaway.name }} on + {{ giveaway.platform }}.

+ +
+
+
Your Key
+

{{ key }}

+
+
+ + Back to Giveaways +
+ + + diff --git a/templates/user_giveaways.html b/templates/user_giveaways.html index b357326..9af6930 100644 --- a/templates/user_giveaways.html +++ b/templates/user_giveaways.html @@ -4,55 +4,34 @@ - User Giveaways + Your Giveaways - -
-

Your Won Giveaways

- {% if giveaways %} - - - - - - - - - - {% for giveaway in giveaways %} - - - - - - {% endfor %} - -
PlatformGameRedeem
{{ giveaway.platform }}{{ giveaway.name }} -
- -
-
- {% else %} -

You have not won any giveaways yet.

- {% endif %} -
+

Your Giveaways

+

Here you can view the giveaways you've won.

+
+ {% if giveaways %} + {% for giveaway in giveaways %} +
+
+
+
{{ giveaway.name }}
+

Platform: {{ giveaway.platform }}

+ Claim Your + Key +
+
+
+ {% endfor %} + {% else %} +

You haven't won any giveaways yet.

+ {% endif %} +
+