def dispatch(self, request: HttpRequest) -> HttpResponse: tenant: Tenant = request.tenant flow = None # First, attempt to get default flow from tenant if self.designation == FlowDesignation.AUTHENTICATION: flow = tenant.flow_authentication if self.designation == FlowDesignation.INVALIDATION: flow = tenant.flow_invalidation # If no flow was set, get the first based on slug and policy if not flow: flow = Flow.with_policy(request, designation=self.designation) # If we still don't have a flow, 404 if not flow: raise Http404 # If user already has a pending plan, clear it so we don't have to later. if SESSION_KEY_PLAN in self.request.session: plan: FlowPlan = self.request.session[SESSION_KEY_PLAN] if plan.flow_pk != flow.pk.hex: LOGGER.warning( "f(def): Found existing plan for other flow, deleting plan", flow_slug=flow.slug, ) del self.request.session[SESSION_KEY_PLAN] return redirect_with_qs("authentik_core:if-flow", request.GET, flow_slug=flow.slug)
def dispatch(self, request: HttpRequest) -> HttpResponse: flow = Flow.with_policy(request, designation=self.designation) if not flow: raise Http404 # If user already has a pending plan, clear it so we don't have to later. if SESSION_KEY_PLAN in self.request.session: plan: FlowPlan = self.request.session[SESSION_KEY_PLAN] if plan.flow_pk != flow.pk.hex: LOGGER.warning( "f(def): Found existing plan for other flow, deleteing plan", flow_slug=flow.slug, ) del self.request.session[SESSION_KEY_PLAN] return redirect_with_qs("authentik_core:if-flow", request.GET, flow_slug=flow.slug)
def recovery(self, request: Request, pk: int) -> Response: """Create a temporary link that a user can use to recover their accounts""" # Check that there is a recovery flow, if not return an error flow = Flow.with_policy(request, designation=FlowDesignation.RECOVERY) if not flow: raise Http404 user: User = self.get_object() token, __ = Token.objects.get_or_create( identifier=f"{user.uid}-password-reset", user=user, intent=TokenIntents.INTENT_RECOVERY, ) querystring = urlencode({"token": token.key}) link = request.build_absolute_uri( reverse_lazy("authentik_flows:default-recovery") + f"?{querystring}") return Response({"link": link})