Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Added "pretty" CSRF error page. Bug 616323.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Wenzel committed Jan 31, 2011
1 parent 731631f commit d9ad078
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
4 changes: 3 additions & 1 deletion settings.py
Expand Up @@ -141,6 +141,8 @@ def __new__(self):

# Templates

CSRF_FAILURE_VIEW = '%s.urls.handler_csrf' % ROOT_PACKAGE

TEMPLATE_DIRS = (
path('templates'),
)
Expand Down Expand Up @@ -258,7 +260,7 @@ def JINJA_CONFIG():
'commonware.middleware.FrameOptionsHeader',
)

ROOT_URLCONF = 'reporter.urls'
ROOT_URLCONF = '%s.urls' % ROOT_PACKAGE

INSTALLED_APPS = [
'input', # comes first so it always takes precedence.
Expand Down
29 changes: 29 additions & 0 deletions templates/csrf_error.html
@@ -0,0 +1,29 @@
{% extends "base.html" %}

{% block content %}
<div class="block prose">
<h2>{% block page_title %}{{ _('CSRF Protection Error') }}{% endblock %}</h2>

<p>
{% trans %}
There was an error verifying your CSRF token. Your request could not be
processed. We apologize for the inconvenience!
{% endtrans %}
</p>

<p>
{% trans cookies_url='http://support.mozilla.com/kb/Cookies' %}
The most likely cause of this error is that your browser is set up
<strong>not to accept cookies</strong> from us. Please follow
<a href="{{ cookies_url }}">these instructions</a> to enable cookies in
Firefox, then try again.
{% endtrans %}
</p>

<p>
{% trans bug_url='https://bugzilla.mozilla.org/enter_bug.cgi?product=Webtools&component=Input' %}
If the problem persists, please <a href="{{ bug_url }}">file a bug.</a> Thanks!
{% endtrans %}
</p>
</div>
{% endblock %}
28 changes: 15 additions & 13 deletions templates/includes/channel_switcher.html
@@ -1,13 +1,15 @@
<form class="channels go" method="get" action="{{ url('dashboard') }}">
<span class="selectbox">
<span>{{ CHANNELS[CHANNEL].pretty }}</span>
<select id="channel" name="channel" dir="ltr">
{% for ch in CHANNEL_USAGE -%}
<option value="{{ ch.short }}" {{ ch.short|ifeq(CHANNEL, "selected") }}>
{{ ch.pretty }}
</option>
{%- endfor %}
</select>
</span>
<button type="submit">{{ _('Go') }}</button>
</form>
{% if CHANNEL %}
<form class="channels go" method="get" action="{{ url('dashboard') }}">
<span class="selectbox">
<span>{{ CHANNELS[CHANNEL].pretty }}</span>
<select id="channel" name="channel" dir="ltr">
{% for ch in CHANNEL_USAGE -%}
<option value="{{ ch.short }}" {{ ch.short|ifeq(CHANNEL, "selected") }}>
{{ ch.pretty }}
</option>
{%- endfor %}
</select>
</span>
<button type="submit">{{ _('Go') }}</button>
</form>
{% endif %}
1 change: 1 addition & 0 deletions urls.py
Expand Up @@ -10,6 +10,7 @@ def _error_page(request, status):
return jingo.render(request, '%d.html' % status, status=status)
handler404 = lambda r: _error_page(r, 404)
handler500 = lambda r: _error_page(r, 500)
handler_csrf = lambda r, reason: jingo.render(r, 'csrf_error.html')


admin.autodiscover()
Expand Down

0 comments on commit d9ad078

Please sign in to comment.