modified: app.py

modified:   templates/redeem_giveaway.html
This commit is contained in:
SimolZimol
2024-09-12 16:01:29 +02:00
parent ea0f27f7f1
commit b673585bf8
2 changed files with 27 additions and 8 deletions

18
app.py
View File

@@ -490,7 +490,7 @@ def user_giveaways():
return redirect(url_for("login")) return redirect(url_for("login"))
@app.route("/user/giveaway/redeem/<uuid>", methods=["GET"]) @app.route("/user/giveaway/redeem/<uuid>", methods=["GET", "POST"])
def redeem_giveaway(uuid): def redeem_giveaway(uuid):
"""Erlaubt dem Benutzer, den Giveaway-Code abzurufen.""" """Erlaubt dem Benutzer, den Giveaway-Code abzurufen."""
if "discord_user" in session: if "discord_user" in session:
@@ -505,14 +505,18 @@ def redeem_giveaway(uuid):
giveaway = cursor.fetchone() giveaway = cursor.fetchone()
if giveaway: if giveaway:
# Setze das Giveaway auf inaktiv, damit es nicht erneut eingelöst werden kann if request.method == "POST":
cursor.execute("UPDATE giveaways SET aktiv = FALSE WHERE uuid = %s", (uuid,)) # Wenn der Benutzer den Key aufdeckt, setze `aktiv` auf TRUE
connection.commit() cursor.execute("UPDATE giveaways SET aktiv = TRUE WHERE uuid = %s", (uuid,))
connection.commit()
# Zeige den Key an # Key aufdecken
return render_template("redeem_giveaway.html", giveaway=giveaway, key=giveaway["game_key"]) 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: 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() cursor.close()
connection.close() connection.close()

View File

@@ -14,14 +14,29 @@
<p class="text-center">Congratulations! You have won the giveaway for <strong>{{ giveaway.name }}</strong> on <p class="text-center">Congratulations! You have won the giveaway for <strong>{{ giveaway.name }}</strong> on
<strong>{{ giveaway.platform }}</strong>.</p> <strong>{{ giveaway.platform }}</strong>.</p>
{% if key %}
<!-- Wenn der Key aufgedeckt wurde -->
<div class="card mt-4"> <div class="card mt-4">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">Your Key</h5> <h5 class="card-title">Your Key</h5>
<p class="card-text">{{ key }}</p> <p class="card-text">{{ key }}</p>
</div> </div>
</div> </div>
<a href="{{ url_for('user_giveaways') }}" class="btn btn-primary mt-4">Back to Giveaways</a> <a href="{{ url_for('user_giveaways') }}" class="btn btn-primary mt-4">Back to Giveaways</a>
{% else %}
<!-- Wenn der Key noch nicht aufgedeckt wurde -->
<div class="card mt-4">
<div class="card-body">
<h5 class="card-title">Claim Your Key</h5>
<p class="card-text">Do you want to reveal your game key? Once revealed, it will be marked as claimed and cannot be undone.</p>
<form method="POST">
<button type="submit" class="btn btn-success">Reveal Key</button>
</form>
</div>
</div>
<a href="{{ url_for('user_giveaways') }}" class="btn btn-secondary mt-4">Back to Giveaways</a>
{% endif %}
</div> </div>
</body> </body>