Commit 6f2af37b by Jason Bau

Merge pull request #47 from Stanford-Online/jbau/direct-access-logout-studio

middleware for CMS logging out all sneakpeek users
parents 57217ed8 19e79a0d
"""
Middleware class handling sneakpeek in cms, which should never be allowed
"""
from student.models import UserProfile
from django.contrib.auth import logout
from django.shortcuts import redirect
class SneakPeekLogoutMiddleware(object):
"""
Middleware that logs out all sneakpeek users and then retries (redirects) the same URL
"""
def process_request(self, request):
"""
logs out all sneakpeek users and then retries (redirects) the same URL
"""
#Do nothing with AnonymousUser
if request.user.is_anonymous():
return None
#Do nothing with non-sneakpeek user
if UserProfile.has_registered(request.user):
return None
logout(request)
return redirect(request.get_full_path())
......@@ -226,6 +226,9 @@ MIDDLEWARE_CLASSES = (
# use Django built in clickjacking protection
'django.middleware.clickjacking.XFrameOptionsMiddleware',
# Log out sneakpeek users
'sneakpeek.middleware.SneakPeekLogoutMiddleware',
)
# Clickjacking protection can be enabled by setting this to 'DENY'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment