From c810628fe37c5eedf6da28035db916aaf8d4d043 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 1 Jan 2023 23:50:57 +0100 Subject: [PATCH] stages/email: use pending user correctly closes #4318 Signed-off-by: Jens Langhammer --- authentik/stages/email/stage.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/authentik/stages/email/stage.py b/authentik/stages/email/stage.py index f931dedc9..7fe4ac757 100644 --- a/authentik/stages/email/stage.py +++ b/authentik/stages/email/stage.py @@ -57,7 +57,7 @@ class EmailStageView(ChallengeStageView): def get_token(self) -> FlowToken: """Get token""" - pending_user = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER] + pending_user = self.get_pending_user() current_stage: EmailStage = self.executor.current_stage valid_delta = timedelta( minutes=current_stage.token_expiry + 1 @@ -82,7 +82,7 @@ class EmailStageView(ChallengeStageView): def send_email(self): """Helper function that sends the actual email. Implies that you've already checked that there is a pending user.""" - pending_user: User = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER] + pending_user = self.get_pending_user() email = self.executor.plan.context.get(PLAN_CONTEXT_EMAIL_OVERRIDE, None) if not email: email = pending_user.email @@ -109,8 +109,9 @@ class EmailStageView(ChallengeStageView): ) and self.executor.plan.context.get(PLAN_CONTEXT_IS_RESTORED, False): messages.success(request, _("Successfully verified Email.")) if self.executor.current_stage.activate_user_on_success: - self.executor.plan.context[PLAN_CONTEXT_PENDING_USER].is_active = True - self.executor.plan.context[PLAN_CONTEXT_PENDING_USER].save() + user = self.get_pending_user() + user.is_active = True + user.save() return self.executor.stage_ok() if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context: self.logger.debug("No pending user")