pConfig = $pConfig; $this->baseUrl = $baseUrl; $this->trustedBrowserRepo = $trustedBrowserRepo; if (!local_user()) { return; } $verified = $this->pConfig->get(local_user(), '2fa', 'verified'); if (!$verified) { $this->baseUrl->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice($this->t('Please enter your password to access this page.')); $this->baseUrl->redirect('settings/2fa'); } } public function post() { if (!local_user()) { return; } if (!empty($_POST['action'])) { self::checkFormSecurityTokenRedirectOnError('settings/2fa/trusted', 'settings_2fa_trusted'); switch ($_POST['action']) { case 'remove_all' : $this->trustedBrowserRepo->removeAllForUser(local_user()); info($this->t('Trusted browsers successfully removed.')); $this->baseUrl->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password')); break; } } if (!empty($_POST['remove_id'])) { self::checkFormSecurityTokenRedirectOnError('settings/2fa/trusted', 'settings_2fa_trusted'); if ($this->trustedBrowserRepo->removeForUser(local_user(), $_POST['remove_id'])) { info($this->t('Trusted browser successfully removed.')); } $this->baseUrl->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password')); } } public function content(): string { parent::content(); $trustedBrowsers = $this->trustedBrowserRepo->selectAllByUid(local_user()); $parser = Parser::create(); $trustedBrowserDisplay = array_map(function (TwoFactor\Model\TrustedBrowser $trustedBrowser) use ($parser) { $dates = [ 'created_ago' => Temporal::getRelativeDate($trustedBrowser->created), 'created_utc' => DateTimeFormat::utc($trustedBrowser->created, 'c'), 'created_local' => DateTimeFormat::local($trustedBrowser->created, 'r'), 'last_used_ago' => Temporal::getRelativeDate($trustedBrowser->last_used), 'last_used_utc' => DateTimeFormat::utc($trustedBrowser->last_used, 'c'), 'last_used_local' => DateTimeFormat::local($trustedBrowser->last_used, 'r'), ]; $result = $parser->parse($trustedBrowser->user_agent); $uaData = [ 'os' => $result->os->family, 'device' => $result->device->family, 'browser' => $result->ua->family, ]; return $trustedBrowser->toArray() + $dates + $uaData; }, $trustedBrowsers->getArrayCopy()); return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/trusted_browsers.tpl'), [ '$form_security_token' => self::getFormSecurityToken('settings_2fa_trusted'), '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'), '$title' => $this->t('Two-factor Trusted Browsers'), '$message' => $this->t('Trusted browsers are individual browsers you chose to skip two-factor authentication to access Friendica. Please use this feature sparingly, as it can negate the benefit of two-factor authentication.'), '$device_label' => $this->t('Device'), '$os_label' => $this->t('OS'), '$browser_label' => $this->t('Browser'), '$created_label' => $this->t('Trusted'), '$last_used_label' => $this->t('Last Use'), '$remove_label' => $this->t('Remove'), '$remove_all_label' => $this->t('Remove All'), '$trusted_browsers' => $trustedBrowserDisplay, ]); } }