moved email sent ammount check into email sending function

This commit is contained in:
2026-01-19 16:39:27 +01:00
parent ad630d65e7
commit 4cbd47dc73

View File

@@ -1,6 +1,6 @@
from flask import Blueprint, render_template, request, flash, redirect, url_for, current_app
from flask_mail import Message
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature, exc
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature
from app.extensions import db, mail, limiter
from app.models import Participant
import traceback
@@ -18,7 +18,8 @@ def add_user(name, email, looking_for_team, on_waitlist = False):
db.session.commit()
return new_user
def send_verification_email(user):
def send_verification_email(user, is_new=True):
if user.num_emails_sent < 5:
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
register_token = s.dumps(user.email, salt='email-confirm-h4tum-ctf-2025')
remove_token = s.dumps(user.email, salt='email-remove-h4tum-ctf-2026')
@@ -31,7 +32,12 @@ def send_verification_email(user):
mail.send(msg)
user.num_emails_sent += 1
db.session.commit()
return True
if is_new:
flash("Registration started! Check your email to confirm your spot.", "success")
else:
flash("Confirmation email resent. Please check your inbox.", "info")
else:
flash("Email limit reached", "error")
def send_waitlist_email(user):
msg = Message('h4tum CTF 2026 Registration', recipients=[user.email])
@@ -63,23 +69,19 @@ def index():
flash("You are already registered and confirmed!", "info")
elif existing_user.on_waitlist:
if confirmed_count < max_spots:
existing_user.on_waitlist = False
db.session.commit()
send_verification_email(existing_user)
flash("Registration started! Check your email to confirm your spot.", "success")
else:
flash("You are already on the waitlist", "info")
else:
if existing_user.num_emails_sent < 5:
flash("Confirmation email resent. Please check your inbox.", "info")
send_verification_email(existing_user)
else:
flash("Email limit reached", "error")
send_verification_email(existing_user, is_new=False)
return redirect(url_for('main.index'))
else:
new_user = add_user(name, email, looking_for_team)
if confirmed_count < max_spots:
send_verification_email(new_user)
flash("Registration started! Check your email to confirm your spot.", "success")
else:
new_user.on_waitlist = True
db.session.commit()