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_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,20 +18,26 @@ def add_user(name, email, looking_for_team, on_waitlist = False):
|
||||
db.session.commit()
|
||||
return new_user
|
||||
|
||||
def send_verification_email(user):
|
||||
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')
|
||||
register_link = url_for('main.verify_email', token=register_token, _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)
|
||||
mail.send(msg)
|
||||
user.num_emails_sent += 1
|
||||
db.session.commit()
|
||||
return True
|
||||
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')
|
||||
register_link = url_for('main.verify_email', token=register_token, _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)
|
||||
mail.send(msg)
|
||||
user.num_emails_sent += 1
|
||||
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):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user