diff --git a/app.py b/app.py index a3ef81d..4bd1f53 100644 --- a/app.py +++ b/app.py @@ -490,7 +490,7 @@ def user_giveaways(): return redirect(url_for("login")) -@app.route("/user/giveaway/redeem/", methods=["GET"]) +@app.route("/user/giveaway/redeem/", methods=["GET", "POST"]) def redeem_giveaway(uuid): """Erlaubt dem Benutzer, den Giveaway-Code abzurufen.""" if "discord_user" in session: @@ -505,14 +505,18 @@ def redeem_giveaway(uuid): 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", (uuid,)) - connection.commit() + if request.method == "POST": + # Wenn der Benutzer den Key aufdeckt, setze `aktiv` auf TRUE + cursor.execute("UPDATE giveaways SET aktiv = TRUE WHERE uuid = %s", (uuid,)) + connection.commit() - # Zeige den Key an - return render_template("redeem_giveaway.html", giveaway=giveaway, key=giveaway["game_key"]) + # Key aufdecken + return render_template("redeem_giveaway.html", giveaway=giveaway, key=giveaway["game_key"]) + + # Zeige die Seite mit dem Button an, um den Key aufzudecken + return render_template("redeem_giveaway.html", giveaway=giveaway, key=None) else: - flash("You are not the winner of this giveaway or the giveaway is no longer active.", "danger") + flash("You are not the winner of this giveaway or the giveaway is no longer available.", "danger") cursor.close() connection.close() diff --git a/templates/redeem_giveaway.html b/templates/redeem_giveaway.html index 7155127..230c9f6 100644 --- a/templates/redeem_giveaway.html +++ b/templates/redeem_giveaway.html @@ -14,14 +14,29 @@

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

+ {% if key %} +
Your Key

{{ key }}

- Back to Giveaways + {% else %} + +
+
+
Claim Your Key
+

Do you want to reveal your game key? Once revealed, it will be marked as claimed and cannot be undone.

+ +
+ +
+
+
+ Back to Giveaways + {% endif %}