Skip to content

Instantly share code, notes, and snippets.

@oertels
Created September 8, 2015 13:01
Show Gist options
  • Save oertels/062946b0592c35bb38e4 to your computer and use it in GitHub Desktop.
Save oertels/062946b0592c35bb38e4 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from django.http import HttpResponseRedirect
from django.conf import settings
class LoginRequired(object):
def __init__(self):
self.login_url = getattr(settings, 'LOGIN_URL', '/accounts/login/')
def process_request(self, request):
"""
Ensure that user is authenticated when accessing a Django-CMS page
"""
if getattr(request, 'current_page', None) and not request.user.is_authenticated():
return HttpResponseRedirect("%s?next=%s" % (self.login_url, request.path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment