Skip to content

Commit

Permalink
envrnm't middleware; disclaimer on hazards of non-prod'n, non-HTTPS site
Browse files Browse the repository at this point in the history
  • Loading branch information
zackmdavis committed Feb 20, 2015
1 parent dfeed00 commit e55f7b1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import settings

class FinetoothEnvironmentMiddleware:
def process_request(self, request):
request.possible_environments = settings.Environment
request.environment = settings.ENVIRONMENT
5 changes: 4 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

Environment = Enum('Environment', ("development", "heroku_demo"))
Environment = Enum('Environment', ("development", "heroku_demo",
# unused as yet---
"production"))

# XXX: surely there must be a better way to detect deployment
# environment at runtime?
Expand Down Expand Up @@ -50,6 +52,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'core.middleware.FinetoothEnvironmentMiddleware'
)

ROOT_URLCONF = 'urls'
Expand Down
19 changes: 19 additions & 0 deletions templates/includes/demo_disclaimer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="alert alert-warning">
<p>
<i class="glyphicon glyphicon-warning-sign"></i>
This instance of the Finetooth software is being run for
<strong>purposes of demonstration only</strong>. The site
operators make no promises about the integrity of your data. (That
is, if we take the site down or delete stuff for some reason or no
reason, we won't feel bad about it.)
</p>
<p>
{% if not request.is_secure %}
Relatedly, this page is <em><strong>not</strong></em> being
served over an encrypted connection! (Sorry.) It is
technologically feasible for third parties to intercept your
password! <strong>Don't reuse a password here</strong> that you
care about being kept secret!
{% endif %}
</p>
</div>
5 changes: 5 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<p>{{ form.errors }}</p>
{% endif %}

{% if request.environment != request.possible_environments.production %}
{% include "includes/demo_disclaimer.html" %}
{% endif %}


<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
Expand Down
5 changes: 5 additions & 0 deletions templates/sign_up.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
{% block subtitle %}Sign up{% endblock %}

{% block content %}

{% if request.environment != request.possible_environments.production %}
{% include "includes/demo_disclaimer.html" %}
{% endif %}

<form action="{% url 'sign_up' %}" method="post">
{% csrf_token %}
{{ signup_form.as_p }}
Expand Down

0 comments on commit e55f7b1

Please sign in to comment.