session = $session; $this->cookie = $cookie; $this->trustedBrowserRepository = $trustedBrowserRepository; } protected function post(array $request = []) { if (!$this->session->getLocalUserId() || !($this->cookie->get('2fa_cookie_hash'))) { return; } $action = $request['action'] ?? ''; if (!empty($action)) { self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_signout'); switch ($action) { case 'trust_and_sign_out': $trusted = $this->cookie->get('2fa_cookie_hash'); $this->cookie->reset(['2fa_cookie_hash' => $trusted]); $this->session->clear(); DI::sysmsg()->addInfo($this->t('Logged out.')); $this->baseUrl->redirect(); break; case 'sign_out': $this->trustedBrowserRepository->removeForUser($this->session->getLocalUserId(), $this->cookie->get('2fa_cookie_hash')); $this->cookie->clear(); $this->session->clear(); DI::sysmsg()->addInfo($this->t('Logged out.')); $this->baseUrl->redirect(); break; default: $this->baseUrl->redirect(); } } } protected function content(array $request = []): string { if (!$this->session->getLocalUserId() || !($this->cookie->get('2fa_cookie_hash'))) { $this->baseUrl->redirect(); } try { $trustedBrowser = $this->trustedBrowserRepository->selectOneByHash($this->cookie->get('2fa_cookie_hash')); if (!$trustedBrowser->trusted) { $trusted = $this->cookie->get('2fa_cookie_hash'); $this->cookie->reset(['2fa_cookie_hash' => $trusted]); $this->session->clear(); DI::sysmsg()->addInfo($this->t('Logged out.')); $this->baseUrl->redirect(); } } catch (TwoFactor\Exception\TrustedBrowserNotFoundException $exception) { $this->cookie->clear(); $this->session->clear(); DI::sysmsg()->addInfo($this->t('Logged out.')); $this->baseUrl->redirect(); } return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/signout.tpl'), [ '$form_security_token' => self::getFormSecurityToken('twofactor_signout'), '$title' => $this->t('Sign out of this browser?'), '$message' => $this->t('

If you trust this browser, you will not be asked for verification code the next time you sign in.

'), '$sign_out_label' => $this->t('Sign out'), '$cancel_label' => $this->t('Cancel'), '$trust_and_sign_out_label' => $this->t('Trust and sign out'), ]); } }