modified: app.py
This commit is contained in:
25
app.py
25
app.py
@@ -477,7 +477,7 @@ def user_giveaways():
|
|||||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||||
cursor = connection.cursor(dictionary=True)
|
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("""
|
cursor.execute("""
|
||||||
SELECT * FROM giveaways WHERE winner_dc_id = %s AND aktiv = TRUE
|
SELECT * FROM giveaways WHERE winner_dc_id = %s AND aktiv = TRUE
|
||||||
""", (user_id,))
|
""", (user_id,))
|
||||||
@@ -486,12 +486,19 @@ def user_giveaways():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
connection.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"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/user/giveaway/redeem/<int:giveaway_id>", methods=["POST"])
|
|
||||||
def redeem_giveaway(giveaway_id):
|
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."""
|
"""Erlaubt dem Benutzer, seinen Giveaway-Preis abzuholen."""
|
||||||
if "discord_user" in session:
|
if "discord_user" in session:
|
||||||
user_info = session["discord_user"]
|
user_info = session["discord_user"]
|
||||||
@@ -500,14 +507,17 @@ def redeem_giveaway(giveaway_id):
|
|||||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
# Überprüfe, ob der eingeloggte Benutzer der Gewinner ist
|
# Überprüfe, ob der eingeloggte Benutzer der Gewinner ist und die UUID übereinstimmt
|
||||||
cursor.execute("SELECT * FROM giveaways WHERE id = %s AND winner_dc_id = %s AND aktiv = TRUE", (giveaway_id, user_id))
|
cursor.execute("""
|
||||||
|
SELECT * FROM giveaways WHERE uuid = %s AND winner_dc_id = %s AND aktiv = TRUE
|
||||||
|
""", (giveaway_uuid, user_id))
|
||||||
giveaway = cursor.fetchone()
|
giveaway = cursor.fetchone()
|
||||||
|
|
||||||
if giveaway:
|
if giveaway:
|
||||||
# Setze das Giveaway auf inaktiv, damit es nicht erneut eingelöst werden kann
|
# 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()
|
connection.commit()
|
||||||
|
|
||||||
flash("You have successfully redeemed your prize!", "success")
|
flash("You have successfully redeemed your prize!", "success")
|
||||||
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 active.", "danger")
|
||||||
@@ -519,6 +529,5 @@ def redeem_giveaway(giveaway_id):
|
|||||||
|
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user