Revert "Replace Module::init() with Constructors"

This commit is contained in:
Hypolite Petovan 2021-11-19 07:23:23 -05:00 committed by GitHub
parent 0b6e0566d7
commit 89d6c89b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 921 additions and 1225 deletions

View file

@ -21,15 +21,11 @@
namespace Friendica\Module\Security;
use Friendica\App\BaseURL;
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\DI;
use Friendica\Model\Profile;
use Friendica\Model\User\Cookie;
use Friendica\Security\TwoFactor;
/**
@ -37,55 +33,33 @@ use Friendica\Security\TwoFactor;
*/
class Logout extends BaseModule
{
/** @var ICanCache */
protected $cache;
/** @var Cookie */
protected $cookie;
/** @var IHandleSessions */
protected $session;
/** @var BaseURL */
protected $baseUrl;
/** @var TwoFactor\Repository\TrustedBrowser */
protected $trustedBrowserRepo;
public function __construct(TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, ICanCache $cache, Cookie $cookie, IHandleSessions $session, BaseURL $baseUrl, L10n $l10n, array $parameters = [])
{
parent::__construct($l10n, $parameters);
$this->cache = $cache;
$this->cookie = $cookie;
$this->session = $session;
$this->baseUrl = $baseUrl;
$this->trustedBrowserRepo = $trustedBrowserRepo;
}
/**
* Process logout requests
*/
public function rawContent()
public function init()
{
$visitor_home = null;
if (remote_user()) {
$visitor_home = Profile::getMyURL();
$this->cache->delete('zrlInit:' . $visitor_home);
DI::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'));
if (DI::cookie()->get('trusted')) {
$trustedBrowserRepository = new TwoFactor\Repository\TrustedBrowser(DI::dba(), DI::logger());
$trustedBrowserRepository->removeForUser(local_user(), DI::cookie()->get('trusted'));
}
$this->cookie->clear();
$this->session->clear();
DI::cookie()->clear();
DI::session()->clear();
if ($visitor_home) {
System::externalRedirect($visitor_home);
} else {
info($this->t('Logged out.'));
$this->baseUrl->redirect();
info(DI::l10n()->t('Logged out.'));
DI::baseUrl()->redirect();
}
}
}