added error handling
This commit is contained in:
@@ -3,6 +3,7 @@ from flask_mail import Message
|
|||||||
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature
|
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
|
||||||
|
|
||||||
bp = Blueprint('main', __name__)
|
bp = Blueprint('main', __name__)
|
||||||
|
|
||||||
@@ -88,16 +89,16 @@ def index():
|
|||||||
def verify_email(token):
|
def verify_email(token):
|
||||||
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
|
s = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
|
||||||
try:
|
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:
|
except SignatureExpired:
|
||||||
return '<h1>Token expired. Please register again.</h1>'
|
return render_template("error.html", error_message="Token expired. Please register again.")
|
||||||
except BadSignature:
|
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()
|
user = Participant.query.filter_by(email=email).first_or_404()
|
||||||
|
|
||||||
if get_confirmed_count() >= current_app.config['MAX_SPOTS']:
|
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
|
user.confirmed = True
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@@ -106,7 +107,7 @@ def verify_email(token):
|
|||||||
discord_token = user.discord_token
|
discord_token = user.discord_token
|
||||||
msg = "You are confirmed!"
|
msg = "You are confirmed!"
|
||||||
if user.looking_for_team:
|
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)
|
return render_template('success.html', message=msg, discord_link=discord_link, discord_token=discord_token)
|
||||||
|
|
||||||
@@ -124,3 +125,17 @@ def impressum():
|
|||||||
@limiter.exempt
|
@limiter.exempt
|
||||||
def rules():
|
def rules():
|
||||||
return render_template('rules.html')
|
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!")
|
||||||
|
|||||||
15
app/templates/error.html
Normal file
15
app/templates/error.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>> Error:</h1>
|
||||||
|
<h1 style="color:#ffffff;">{{ error_message }}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
14
app/templates/ratelimit_error.html
Normal file
14
app/templates/ratelimit_error.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>> Ratelimit exceeded:</h1>
|
||||||
|
<h1 style="color:#ffffff;">{{ error_message }}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user