Skip to main content

Example policy snippets

The following are examples of policies that can be used with flows.

Redirect current flow to another URL​

This policy should be bound to the stage after your redirect should happen. For example, if you have an identification and a password stage, and you want to redirect after identification, bind the policy to the password stage. Make sure the stage binding's option Evaluate when stage is run is enabled.

plan = request.context.get("flow_plan")
if not plan:
return False
plan.redirect("https://foo.bar")
return False

Deny flow when user is authenticated​

Set the flow's Denied action to CONTINUE. This will redirect already authenticated users to the default interface if they try to use the respective flow.

return not request.user.is_authenticated