. * */ namespace Friendica\Module\Security; use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Cache\Capability\ICanCache; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\System; use Friendica\Model\Profile; use Friendica\Model\User\Cookie; use Friendica\Module\Response; use Friendica\Security\TwoFactor; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; /** * Logout module */ class Logout extends BaseModule { /** @var ICanCache */ protected $cache; /** @var Cookie */ protected $cookie; /** @var IHandleSessions */ protected $session; /** @var TwoFactor\Repository\TrustedBrowser */ protected $trustedBrowserRepo; public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, ICanCache $cache, Cookie $cookie, IHandleSessions $session, array $server, array $parameters = []) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); $this->cache = $cache; $this->cookie = $cookie; $this->session = $session; $this->trustedBrowserRepo = $trustedBrowserRepo; } /** * Process logout requests */ protected function rawContent(array $request = []) { $visitor_home = null; if (remote_user()) { $visitor_home = Profile::getMyURL(); $this->cache->delete('zrlInit:' . $visitor_home); } Hook::callAll("logging_out"); // Remove this trusted browser as it won't be able to be used ever again after the cookie is cleared if ($this->cookie->get('trusted')) { $this->trustedBrowserRepo->removeForUser(local_user(), $this->cookie->get('trusted')); } $this->cookie->clear(); $this->session->clear(); if ($visitor_home) { System::externalRedirect($visitor_home); } else { info($this->t('Logged out.')); $this->baseUrl->redirect(); } } }