Skip to content

Instantly share code, notes, and snippets.

@luhn
Created January 28, 2015 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luhn/47d418a04186e8740585 to your computer and use it in GitHub Desktop.
Save luhn/47d418a04186e8740585 to your computer and use it in GitHub Desktop.
@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