modified: app.py
new file: templates/redeem_giveaway.html modified: templates/user_giveaways.html
This commit is contained in:
26
app.py
26
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 (winner_dc_id)
|
# Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist
|
||||||
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,20 +486,13 @@ def user_giveaways():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
if won_giveaways:
|
|
||||||
return render_template("user_giveaways.html", user_info=user_info, giveaways=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/<uuid>", methods=["GET"])
|
||||||
return redirect(url_for("login"))
|
def redeem_giveaway(uuid):
|
||||||
|
"""Erlaubt dem Benutzer, den Giveaway-Code abzurufen."""
|
||||||
@app.route("/user/giveaway/redeem/<uuid:giveaway_uuid>", methods=["POST"])
|
|
||||||
def redeem_giveaway(giveaway_uuid):
|
|
||||||
"""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"]
|
||||||
user_id = user_info["id"]
|
user_id = user_info["id"]
|
||||||
@@ -507,18 +500,17 @@ def redeem_giveaway(giveaway_uuid):
|
|||||||
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 und die UUID übereinstimmt
|
# Überprüfen, ob der eingeloggte Benutzer der Gewinner ist
|
||||||
cursor.execute("""
|
cursor.execute("SELECT * FROM giveaways WHERE uuid = %s AND winner_dc_id = %s AND aktiv = TRUE", (uuid, user_id))
|
||||||
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 uuid = %s", (giveaway_uuid,))
|
cursor.execute("UPDATE giveaways SET aktiv = FALSE WHERE uuid = %s", (uuid,))
|
||||||
connection.commit()
|
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:
|
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")
|
||||||
|
|
||||||
|
|||||||
28
templates/redeem_giveaway.html
Normal file
28
templates/redeem_giveaway.html
Normal 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>
|
||||||
@@ -4,55 +4,34 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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">
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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">
|
<div class="container mt-5">
|
||||||
<h1 class="text-center">Your Won Giveaways</h1>
|
<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 %}
|
{% 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 %}
|
{% for giveaway in giveaways %}
|
||||||
<tr>
|
<div class="col-md-4">
|
||||||
<td>{{ giveaway.platform }}</td>
|
<div class="card">
|
||||||
<td>{{ giveaway.name }}</td>
|
<div class="card-body">
|
||||||
<td>
|
<h5 class="card-title">{{ giveaway.name }}</h5>
|
||||||
<form method="POST" action="{{ url_for('redeem_giveaway', giveaway_uuid=giveaway.uuid) }}">
|
<p class="card-text">Platform: {{ giveaway.platform }}</p>
|
||||||
<button type="submit" class="btn btn-success">Redeem</button>
|
<a href="{{ url_for('redeem_giveaway', uuid=giveaway.uuid) }}" class="btn btn-primary">Claim Your
|
||||||
</form>
|
Key</a>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<p class="text-center">You have not won any giveaways yet.</p>
|
<p class="text-center">You haven't won any giveaways yet.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user