Skip to main content

Simple middleware to restrict access to "private beta" sites

Project description

This is a simple Django app with middleware to block access (in a user-friendly, but not particularly secure way) to early beta or testing sites.

The middleware checks for the presence of a session token. If it matches the token specified in settings, the request procedes normally; if it doesn’t, the middleware displays a “please enter the token” form instead. A single token is shared for all authorized viewers.

The point is not to provide high security, but to instead prevent casual visitors and crawlers from poking around a beta or testing site, while at the same time making it super easy to give access to designers and people of varying computer literacy. You just have to tell them: “Oh, the magic word is ‘fiddlesticks’”, and they can instantly get access without having to do any sort of registration. The goal is to be nicer user experience than HTTP basic auth for this purpose.

Installation

Get it into your path. This ought to work:

pip install -e http://github.com/yourcelf/django-fence.git

Usage

  1. Add fence to INSTALLED_APPS:

    INSTALLED_APPS += ('fence',)
  2. Add middleware:

    MIDDLEWARE_CLASSES += ("fence.middleware.Fence",)
  3. Define the magic word:

    FENCE_TOKEN = "secret"
  4. Create a template to display in fence/say_the_magic_word.html. An example template:

    {% extends "base.html" %}
    
    {# Add a class to <body> which lets us hide footers/headers/etc. #}
    {% block body_class %}front-gate{% endblock %}
    
    {% block content %}
    
        <form method='post' action=''>{% csrf_token %}
            <p>We're still in beta.  What's the magic word?</p>
            {{ form }}
            <input type='submit' value='Let me in!' />
        </form>
    
    {% endblock %}

License

MIT License.

Copyright (C) 2012 Charlie DeTar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Authors

By Charlie DeTar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fence-0.0.3.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file django-fence-0.0.3.tar.gz.

File metadata

  • Download URL: django-fence-0.0.3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-fence-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0d49ee708e0c7da21945cc727e58310a04a4a231352943178ee7a9214c045221
MD5 2879c0c1ad3d0e14fd41c57f3988212b
BLAKE2b-256 02d3600c877036e78425ef1396af17bb2aa05b5c7d0fa5da6087cc3b17db878a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page