Skip to content
This repository was archived by the owner on Jan 31, 2018. It is now read-only.

Commit c4f8091

Browse files
Joshua Smithwillkg
authored andcommitted
[bug 857734] Write better csrf error page
1 parent cfc3814 commit c4f8091

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "base.html" %}
2+
3+
{% block page_title %}{{ _('CSRF Failure') }}{% endblock %}
4+
5+
{% block content %}
6+
<div class="col"></div>
7+
<div class="col wide">
8+
<div class="block">
9+
{% include "includes/csrf_failure_text.html" %}
10+
</div>
11+
</div>
12+
{% endblock %}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1>{{ _('CSRF Failure') }}</h1>
2+
<p>
3+
{% trans %}
4+
Your submission failed a security check on our system.
5+
{% endtrans %}
6+
</p>
7+
<p>
8+
{% trans %}
9+
Please make sure you have cookies enabled, press the Back button in your
10+
browser, refresh the page, fill out the form, and try submitting your
11+
feedback again.
12+
{% endtrans %}
13+
</p>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "mobile/base.html" %}
2+
3+
{% block page_title %}{{ _('CSRF Failure') }}{% endblock %}
4+
5+
{% block content %}
6+
<article>
7+
<section>
8+
{% include "includes/csrf_failure_text.html" %}
9+
</section>
10+
</article>
11+
{% endblock %}

fjord/base/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from functools import wraps
44

55
from django.conf import settings
6-
from django.http import Http404, HttpResponse, HttpResponseRedirect
6+
from django.http import Http404, HttpResponse, HttpResponseForbidden, HttpResponseRedirect
77
from django.shortcuts import render
88
from django.utils.http import is_safe_url
99
from django.views.decorators.cache import never_cache
@@ -54,6 +54,11 @@ def login_failure(request, template=None):
5454
return render(request, template)
5555

5656

57+
@mobile_template('{mobile/}csrf_failure.html')
58+
def csrf_failure(request, reason='', template=None):
59+
return HttpResponseForbidden(render(request, template), content_type='text/html')
60+
61+
5762
@mobile_template('{mobile/}about.html')
5863
def about_view(request, template=None):
5964
return render(request, template)

fjord/settings/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@
325325
# Always generate a CSRF token for anonymous users.
326326
ANON_ALWAYS = True
327327

328+
# CSRF error page
329+
CSRF_FAILURE_VIEW = 'fjord.base.views.csrf_failure'
330+
328331
# Tells the extract script what files to look for L10n in and what
329332
# function handles the extraction. The Tower library expects this.
330333
DOMAIN_METHODS['messages'] = [

0 commit comments

Comments
 (0)