added error handling
This commit is contained in:
@@ -3,6 +3,7 @@ from flask_mail import Message
|
||||
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature
|
||||
from app.extensions import db, mail, limiter
|
||||
from app.models import Participant
|
||||
import traceback
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
@@ -88,16 +89,16 @@ def index():
|
||||
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)
|
||||
email = s.loads(token, salt='email-confirm-h4tum-ctf-2025', max_age=28800)
|
||||
except SignatureExpired:
|
||||
return '<h1>Token expired. Please register again.</h1>'
|
||||
return render_template("error.html", error_message="Token expired. Please register again.")
|
||||
except BadSignature:
|
||||
return '<h1>Invalid token.</h1>'
|
||||
return render_template("error.html", error_message="Invalid token.")
|
||||
|
||||
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>'
|
||||
return render_template("error.html", error_message="Sorry! The event filled up while you were verifying.")
|
||||
|
||||
user.confirmed = True
|
||||
db.session.commit()
|
||||
@@ -106,7 +107,7 @@ def verify_email(token):
|
||||
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."
|
||||
msg += " Since you need a team, please join the #team-search channel."
|
||||
|
||||
return render_template('success.html', message=msg, discord_link=discord_link, discord_token=discord_token)
|
||||
|
||||
@@ -124,3 +125,17 @@ def impressum():
|
||||
@limiter.exempt
|
||||
def rules():
|
||||
return render_template('rules.html')
|
||||
|
||||
@bp.errorhandler(429)
|
||||
def ratelimit_handler(e):
|
||||
return render_template("ratelimit_error.html", error_message=e.description)
|
||||
|
||||
@bp.errorhandler(500)
|
||||
def server_error(e):
|
||||
msg = Message('500 Error on registration Website', recipients=["simon.bussmann@tum.de"])
|
||||
full_traceback = traceback.format_exc()
|
||||
|
||||
msg.body = f"An error occurred during registration:\n\n{full_traceback}"
|
||||
mail.send(msg)
|
||||
|
||||
return render_template("error.html", error_message="Internal Server Error. Admin has been notified!")
|
||||
|
||||
Reference in New Issue
Block a user