modified: app.py

new file:   templates/redeem_giveaway.html
	modified:   templates/user_giveaways.html
This commit is contained in:
SimolZimol
2024-09-12 15:53:25 +02:00
parent 72eb412f09
commit 3d7be7c533
3 changed files with 60 additions and 61 deletions

28
app.py
View File

@@ -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")

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redeem Giveaway</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center">Giveaway Prize</h1>
<p class="text-center">Congratulations! You have won the giveaway for <strong>{{ giveaway.name }}</strong> on
<strong>{{ giveaway.platform }}</strong>.</p>
<div class="card mt-4">
<div class="card-body">
<h5 class="card-title">Your Key</h5>
<p class="card-text">{{ key }}</p>
</div>
</div>
<a href="{{ url_for('user_giveaways') }}" class="btn btn-primary mt-4">Back to Giveaways</a>
</div>
</body>
</html>

View File

@@ -4,55 +4,34 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Giveaways</title>
<title>Your Giveaways</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Giveaways</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('user_dashboard') }}">User Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('logout') }}">Logout</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-5">
<h1 class="text-center">Your Won Giveaways</h1>
{% if giveaways %}
<table class="table table-striped">
<thead>
<tr>
<th>Platform</th>
<th>Game</th>
<th>Redeem</th>
</tr>
</thead>
<tbody>
{% for giveaway in giveaways %}
<tr>
<td>{{ giveaway.platform }}</td>
<td>{{ giveaway.name }}</td>
<td>
<form method="POST" action="{{ url_for('redeem_giveaway', giveaway_uuid=giveaway.uuid) }}">
<button type="submit" class="btn btn-success">Redeem</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-center">You have not won any giveaways yet.</p>
{% endif %}
</div>
<h1 class="text-center">Your Giveaways</h1>
<p class="text-center">Here you can view the giveaways you've won.</p>
<div class="row mt-4">
{% if giveaways %}
{% for giveaway in giveaways %}
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ giveaway.name }}</h5>
<p class="card-text">Platform: {{ giveaway.platform }}</p>
<a href="{{ url_for('redeem_giveaway', uuid=giveaway.uuid) }}" class="btn btn-primary">Claim Your
Key</a>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-center">You haven't won any giveaways yet.</p>
{% endif %}
</div>
</div>
</body>
</html>