moved email sent ammount check into email sending function
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from flask import Blueprint, render_template, request, flash, redirect, url_for, current_app
|
from flask import Blueprint, render_template, request, flash, redirect, url_for, current_app
|
||||||
from flask_mail import Message
|
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.extensions import db, mail, limiter
|
||||||
from app.models import Participant
|
from app.models import Participant
|
||||||
import traceback
|
import traceback
|
||||||
@@ -18,20 +18,26 @@ def add_user(name, email, looking_for_team, on_waitlist = False):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return new_user
|
return new_user
|
||||||
|
|
||||||
def send_verification_email(user):
|
def send_verification_email(user, is_new=True):
|
||||||
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
|
if user.num_emails_sent < 5:
|
||||||
register_token = s.dumps(user.email, salt='email-confirm-h4tum-ctf-2025')
|
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
|
||||||
remove_token = s.dumps(user.email, salt='email-remove-h4tum-ctf-2026')
|
register_token = s.dumps(user.email, salt='email-confirm-h4tum-ctf-2025')
|
||||||
register_link = url_for('main.verify_email', token=register_token, _external=True)
|
remove_token = s.dumps(user.email, salt='email-remove-h4tum-ctf-2026')
|
||||||
remove_link = url_for('main.remove_registration', token=remove_token, _external=True)
|
register_link = url_for('main.verify_email', token=register_token, _external=True)
|
||||||
logo = url_for('static', filename='h4tum_white.png', _external=True)
|
remove_link = url_for('main.remove_registration', token=remove_token, _external=True)
|
||||||
|
logo = url_for('static', filename='h4tum_white.png', _external=True)
|
||||||
msg = Message('Verify your CTF Registration', recipients=[user.email])
|
|
||||||
msg.html = render_template("email.html", user_name=user.name, register_link=register_link, remove_link=remove_link, logo_url=logo)
|
msg = Message('Verify your CTF Registration', recipients=[user.email])
|
||||||
mail.send(msg)
|
msg.html = render_template("email.html", user_name=user.name, register_link=register_link, remove_link=remove_link, logo_url=logo)
|
||||||
user.num_emails_sent += 1
|
mail.send(msg)
|
||||||
db.session.commit()
|
user.num_emails_sent += 1
|
||||||
return True
|
db.session.commit()
|
||||||
|
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):
|
def send_waitlist_email(user):
|
||||||
msg = Message('h4tum CTF 2026 Registration', recipients=[user.email])
|
msg = Message('h4tum CTF 2026 Registration', recipients=[user.email])
|
||||||
@@ -63,23 +69,19 @@ def index():
|
|||||||
flash("You are already registered and confirmed!", "info")
|
flash("You are already registered and confirmed!", "info")
|
||||||
elif existing_user.on_waitlist:
|
elif existing_user.on_waitlist:
|
||||||
if confirmed_count < max_spots:
|
if confirmed_count < max_spots:
|
||||||
|
existing_user.on_waitlist = False
|
||||||
|
db.session.commit()
|
||||||
send_verification_email(existing_user)
|
send_verification_email(existing_user)
|
||||||
flash("Registration started! Check your email to confirm your spot.", "success")
|
|
||||||
else:
|
else:
|
||||||
flash("You are already on the waitlist", "info")
|
flash("You are already on the waitlist", "info")
|
||||||
else:
|
else:
|
||||||
if existing_user.num_emails_sent < 5:
|
send_verification_email(existing_user, is_new=False)
|
||||||
flash("Confirmation email resent. Please check your inbox.", "info")
|
|
||||||
send_verification_email(existing_user)
|
|
||||||
else:
|
|
||||||
flash("Email limit reached", "error")
|
|
||||||
return redirect(url_for('main.index'))
|
return redirect(url_for('main.index'))
|
||||||
else:
|
else:
|
||||||
new_user = add_user(name, email, looking_for_team)
|
new_user = add_user(name, email, looking_for_team)
|
||||||
|
|
||||||
if confirmed_count < max_spots:
|
if confirmed_count < max_spots:
|
||||||
send_verification_email(new_user)
|
send_verification_email(new_user)
|
||||||
flash("Registration started! Check your email to confirm your spot.", "success")
|
|
||||||
else:
|
else:
|
||||||
new_user.on_waitlist = True
|
new_user.on_waitlist = True
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user