Skip to content

Instantly share code, notes, and snippets.

@buchi
Last active December 4, 2015 08:21
Show Gist options
  • Save buchi/15bc868ad47d1c3e155c to your computer and use it in GitHub Desktop.
Save buchi/15bc868ad47d1c3e155c to your computer and use it in GitHub Desktop.
require_login.py (Fix for links to authenticated Plone content from MS Office)
from Products.PythonScripts.standard import url_unquote
login = 'login'
portal = context.portal_url.getPortalObject()
# if cookie crumbler did a traverse instead of a redirect,
# this would be the way to get the value of came_from
#url = portal.getCurrentUrl()
#context.REQUEST.set('came_from', url)
if context.portal_membership.isAnonymousUser():
return portal.restrictedTraverse(login)()
else:
came_from = url_unquote(context.REQUEST.get('came_from', ''))
location = came_from.split('?')[0]
try:
# Attempt a traverse to the given path
portal.restrictedTraverse(location.replace(
portal.absolute_url() + '/', ''))
container.REQUEST.RESPONSE.redirect(came_from)
except:
return portal.restrictedTraverse('insufficient_privileges')()
@buchi
Copy link
Author

buchi commented Dec 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment