Skip to content

Instantly share code, notes, and snippets.

@phaer
Last active December 23, 2015 07:28
Show Gist options
  • Save phaer/6600688 to your computer and use it in GitHub Desktop.
Save phaer/6600688 to your computer and use it in GitHub Desktop.
Mediagoblin m*e*ddleware to keep your instance private.
from mediagoblin.meddleware import BaseMeddleware
from mediagoblin.tools.response import redirect
class PrivateMeddleware(BaseMeddleware):
"""Private Meddleware
Redirects requests by unauthenticated clients to the login form.
"""
public_views = [
'mediagoblin.auth.login',
'mediagoblin.plugins.basic_auth.forgot_password',
'mediagoblin.plugins.basic_auth.verify_forgot_password',
'mediagoblin.plugins.api.test',
'mediagoblin.plugins.api.entries',
'mediagoblin.plugins.api.post_entry',
]
def process_request(self, request, controller):
public_urls = map(request.urlgen, self.public_views)
# TODO: check atom feeds with authentication.
if not request.path in public_urls and not request.user:
return redirect(request, 'mediagoblin.auth.login')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment