modified: app.py
new file: templates/redeem_giveaway.html modified: templates/user_giveaways.html
This commit is contained in:
28
app.py
28
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/<uuid:giveaway_uuid>", methods=["POST"])
|
||||
def redeem_giveaway(giveaway_uuid):
|
||||
"""Erlaubt dem Benutzer, seinen Giveaway-Preis abzuholen."""
|
||||
@app.route("/user/giveaway/redeem/<uuid>", 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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user