WIP registration platform + discord bot
This commit is contained in:
21
app/__init__.py
Normal file
21
app/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from flask import Flask
|
||||
from app.config import Config
|
||||
from app.extensions import db, mail
|
||||
|
||||
def create_app(config_class=Config):
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config_class)
|
||||
|
||||
# Initialize extensions
|
||||
db.init_app(app)
|
||||
mail.init_app(app)
|
||||
|
||||
# Register Blueprints
|
||||
from app.routes import bp as main_bp
|
||||
app.register_blueprint(main_bp)
|
||||
|
||||
# Create DB tables
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
return app
|
||||
21
app/config.py.example
Normal file
21
app/config.py.example
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
class Config:
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY')
|
||||
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
|
||||
'sqlite:///' + os.path.join(basedir, '../instance/registration.db')
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
# Email Settings (Update these!)
|
||||
MAIL_SERVER =
|
||||
MAIL_PORT =
|
||||
MAIL_USE_TLS = True
|
||||
MAIL_USERNAME = os.environ.get('EMAIL_USER')
|
||||
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')
|
||||
MAIL_DEFAULT_SENDER = os.environ.get('EMAIL_USER')
|
||||
|
||||
MAX_SPOTS =
|
||||
TUM_DOMAIN = "tum.de"
|
||||
DISCORD_LINK =
|
||||
5
app/extensions.py
Normal file
5
app/extensions.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_mail import Mail
|
||||
|
||||
db = SQLAlchemy()
|
||||
mail = Mail()
|
||||
21
app/models.py
Normal file
21
app/models.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from app.extensions import db
|
||||
import secrets
|
||||
|
||||
class Participant(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(100), nullable=False)
|
||||
email = db.Column(db.String(120), unique=True, nullable=False)
|
||||
looking_for_team = db.Column(db.Boolean, default=False)
|
||||
confirmed = db.Column(db.Boolean, default=False)
|
||||
discord_token = db.Column(db.String(16), unique=True)
|
||||
discord_user_id = db.Column(db.String(50))
|
||||
|
||||
def __init__(self, name : str, email : str, looking_for_team : bool) -> None:
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.email = email
|
||||
self.looking_for_team = looking_for_team
|
||||
self.discord_token = secrets.token_hex(8)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Participant {self.email}>'
|
||||
84
app/routes.py
Normal file
84
app/routes.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from flask import Blueprint, render_template, request, flash, redirect, url_for, current_app
|
||||
from flask_mail import Message
|
||||
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature
|
||||
from app.extensions import db, mail
|
||||
from app.models import Participant
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
def get_confirmed_count():
|
||||
return Participant.query.filter_by(confirmed=True).count()
|
||||
|
||||
def send_verification_email(user_email):
|
||||
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
|
||||
token = s.dumps(user_email, salt='email-confirm-h4tum-ctf-2025')
|
||||
link = url_for('main.verify_email', token=token, _external=True)
|
||||
|
||||
#msg = Message('Verify your CTF Registration', recipients=[user_email])
|
||||
#msg.body = f'Click here to confirm your spot: {link}'
|
||||
print(link)
|
||||
|
||||
@bp.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
confirmed_count = get_confirmed_count()
|
||||
max_spots = current_app.config['MAX_SPOTS']
|
||||
spots_left = max_spots - confirmed_count
|
||||
|
||||
if request.method == 'POST':
|
||||
name = request.form['name']
|
||||
email = request.form['email'].lower().strip()
|
||||
looking_for_team = True if request.form.get('looking_for_team') else False
|
||||
|
||||
tum_domain = current_app.config['TUM_DOMAIN']
|
||||
if not email.endswith(f"@{tum_domain}"):
|
||||
flash(f"Error: You must use a @{tum_domain} email address.", "error")
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
if confirmed_count >= max_spots:
|
||||
flash("Sorry, the event is full!", "error")
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
existing_user = Participant.query.filter_by(email=email).first()
|
||||
if existing_user:
|
||||
if existing_user.confirmed:
|
||||
flash("You are already registered and confirmed!", "info")
|
||||
else:
|
||||
flash("Confirmation email resent. Please check your inbox.", "info")
|
||||
send_verification_email(email)
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
new_user = Participant(name=name, email=email, looking_for_team=looking_for_team)
|
||||
db.session.add(new_user)
|
||||
db.session.commit()
|
||||
|
||||
send_verification_email(email)
|
||||
flash("Registration started! Check your email to confirm your spot.", "success")
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
return render_template('index.html', spots_left=spots_left)
|
||||
|
||||
@bp.route('/verify/<token>')
|
||||
def verify_email(token):
|
||||
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
|
||||
try:
|
||||
email = s.loads(token, salt='email-confirm-h4tum-ctf-2025', max_age=3600)
|
||||
except SignatureExpired:
|
||||
return '<h1>Token expired. Please register again.</h1>'
|
||||
except BadSignature:
|
||||
return '<h1>Invalid token.</h1>'
|
||||
|
||||
user = Participant.query.filter_by(email=email).first_or_404()
|
||||
|
||||
if get_confirmed_count() >= current_app.config['MAX_SPOTS']:
|
||||
return '<h1>Sorry! The event filled up while you were verifying.</h1>'
|
||||
|
||||
user.confirmed = True
|
||||
db.session.commit()
|
||||
|
||||
discord_link = current_app.config['DISCORD_LINK']
|
||||
discord_token = user.discord_token
|
||||
msg = "You are confirmed!"
|
||||
if user.looking_for_team:
|
||||
msg += " Since you need a team, please join the #looking-for-group channel."
|
||||
|
||||
return render_template('success.html', message=msg, discord_link=discord_link, discord_token=discord_token)
|
||||
1
app/static/style.css
Normal file
1
app/static/style.css
Normal file
@@ -0,0 +1 @@
|
||||
/* Styles are inline in HTML for simplicity, but this file is created for structure */
|
||||
113
app/templates/index.html
Normal file
113
app/templates/index.html
Normal file
@@ -0,0 +1,113 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TUM CTF Registration</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Courier New', monospace;
|
||||
background: #1a1a1a;
|
||||
color: #00ff00;
|
||||
margin: 0;
|
||||
padding: 10px; /* Reduced for mobile */
|
||||
font-size: 18px; /* Balanced size for readability */
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px; /* Prevents it from stretching too wide on desktop */
|
||||
margin: 20px auto;
|
||||
background: #222;
|
||||
padding: 20px;
|
||||
border: 1px solid #00ff00;
|
||||
box-sizing: border-box; /* Ensures padding doesn't break layout */
|
||||
}
|
||||
|
||||
h1 { font-size: 1.5rem; word-wrap: break-word; }
|
||||
|
||||
input[type="text"], input[type="email"] {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
margin: 10px 0;
|
||||
background: #000;
|
||||
color: #00ff00;
|
||||
border: 1px solid #00ff00;
|
||||
box-sizing: border-box;
|
||||
font-size: 16px; /* Prevents iOS from zooming in on focus */
|
||||
}
|
||||
|
||||
button {
|
||||
background: #00ff00;
|
||||
color: #000;
|
||||
padding: 15px 20px;
|
||||
border: none;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
width: 100%; /* Full width button is easier to tap on mobile */
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.alert { padding: 10px; margin-bottom: 10px; border: 1px solid white; font-size: 14px; }
|
||||
.alert.error { border-color: red; color: red; }
|
||||
.alert.success { border-color: #00ff00; }
|
||||
|
||||
ul { padding-left: 20px; }
|
||||
li { margin-bottom: 10px; }
|
||||
|
||||
/* Small screen adjustments */
|
||||
@media (max-width: 480px) {
|
||||
body { font-size: 16px; }
|
||||
.container { padding: 15px; }
|
||||
h1 { font-size: 1.2rem; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>> TUM CTF 2025_</h1>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert {{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="status">
|
||||
<h2>Spots Remaining: {{ spots_left }} / 84</h2>
|
||||
</div>
|
||||
|
||||
{% if spots_left > 0 %}
|
||||
<form method="POST">
|
||||
<label>Name</label>
|
||||
<input type="text" name="name" required>
|
||||
|
||||
<label>TUM Email</label>
|
||||
<input type="email" name="email" placeholder="@tum.de" required>
|
||||
|
||||
<label style="display:block; margin: 20px 0; line-height: 1.4;">
|
||||
<input type="checkbox" name="looking_for_team" style="transform: scale(1.2); margin-right: 10px;">
|
||||
[ ] I need a team / looking for group
|
||||
</label>
|
||||
|
||||
<button type="submit">INITIALIZE_REGISTRATION</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<h2 style="color:red">EVENT FULL</h2>
|
||||
{% endif %}
|
||||
|
||||
<hr style="border-color: #333; margin: 30px 0;">
|
||||
|
||||
<div class="info">
|
||||
<h3>> SYSTEM_INFO</h3>
|
||||
<ul>
|
||||
<li><strong>Team Size:</strong> 4 People</li>
|
||||
<li><strong>Location:</strong> MI Rechnerhalle, Garching</li>
|
||||
<li><strong>Date:</strong> 16.01.2026 12:00</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
44
app/templates/success.html
Normal file
44
app/templates/success.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Access Granted</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: monospace;
|
||||
background: #1a1a1a;
|
||||
color: #00ff00;
|
||||
|
||||
/* The centering magic */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center; /* Vertical center */
|
||||
align-items: center; /* Horizontal center */
|
||||
height: 100vh; /* Uses full viewport height */
|
||||
margin: 0; /* Removes default browser margins */
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 5rem; /* Makes it "Big" */
|
||||
margin-bottom: 10px;
|
||||
text-shadow: 0 0 10px #00ff00; /* Adds a hacker glow */
|
||||
}
|
||||
|
||||
a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ACCESS GRANTED</h1>
|
||||
<h2>{{ message }}</h2>
|
||||
<h2>
|
||||
<a href="{{ discord_link }}">Join the Discord server</a>
|
||||
| Access Token: {{ discord_token }}
|
||||
</h2>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user