Created
January 28, 2015 18:59
-
-
Save luhn/47d418a04186e8740585 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@view_config(context=Forbidden, renderer='renderer.pt') | |
def forbidden(context, request): | |
# If unauthenticated, redirect to sign in | |
if( | |
Authenticated not in request.effective_principals | |
and request.unauthenticated_userid is None | |
): | |
raise HTTPFound('auth redirect') | |
# If unverified and verification would help, redirect to verification | |
principals = request.effective_principals | |
denial = context.result | |
if( | |
Authenticated in principals | |
and Verified not in principals | |
and denial is not None | |
and isinstance(denial, ACLPermitsResult) | |
): | |
principals.append(Verified) | |
policy = request.registry.queryUtility(IAuthorizationPolicy) | |
if policy.permits(denial.context, principals, denial.permission): | |
raise HTTPFound('verify redirect') | |
return { | |
'title': '403 Forbidden', | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment