Last active
December 4, 2015 08:21
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://support.microsoft.com/en-us/kb/899927