diff --git a/SciPost_v1/settings/base.py b/SciPost_v1/settings/base.py index 5a5468d6df9aa34e0204a18d1029a0e75d713f41..0ca208465dd5f4706ee6a3421d8bb91d4eee9e0c 100644 --- a/SciPost_v1/settings/base.py +++ b/SciPost_v1/settings/base.py @@ -261,6 +261,7 @@ WEBPACK_LOADER = { # Email EMAIL_BACKEND = 'mails.backends.extendedfilebased.EmailBackend' EMAIL_FILE_PATH = 'local_files/email/' +EMAIL_SUBJECT_PREFIX = '[SciPost Server] ' MAILCHIMP_DATABASE_CODE = 'us6' MAILCHIMP_API_USER = 'test_API-user' MAILCHIMP_API_KEY = 'test_API-key' @@ -310,3 +311,5 @@ AUTH_PASSWORD_VALIDATORS = [ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] + +CSRF_FAILURE_VIEW = 'scipost.views.csrf_failure' diff --git a/scipost/views.py b/scipost/views.py index 858b004e79829bd2f4ae61483d1714def50eebdb..a29e63996719a1089bbdc1693534814093f6c707 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -1316,3 +1316,13 @@ class AboutView(ListView): )) context['object_list'] = object_list return context + + +def csrf_failure(request, reason=""): + """ + Custom CRSF Failure. Informing admins via email as well. + """ + body = 'Error message: ' + reason + '\nUser: ' + str(request.user) + body += '\nRequest GET: ' + str(request.GET) + '\nRequest POST: ' + str(request.POST) + mail.mail_admins('CRSF Failure', body) + return render(request, 'crsf-failure.html') diff --git a/templates/crsf-failure.html b/templates/crsf-failure.html new file mode 100644 index 0000000000000000000000000000000000000000..60d2fbb32dba68b2acbdb7e9254822ad0f1d2505 --- /dev/null +++ b/templates/crsf-failure.html @@ -0,0 +1,14 @@ +{% extends 'scipost/base.html' %} + +{% block pagetitle %}: 500{% endblock pagetitle %} + +{% block content %} + +<div style="text-align: center;"> + <img src="//scipost.org/static/scipost/images/logo_scipost_RGB_HTML_groot.png" alt="SciPost logo" width="240" style="margin-top: 20px; margin-bottom: 20px" /> + <h2>We are sorry, your security token seem to have expired. Please refresh your page and try again.</h2> + <h3>The SciPost administrators have been informed.</h3> + <p style="margin-top: 20px;">Go back to <a href="//scipost.org">the homepage</a>.</p> +</div> + +{% endblock %}