2018-02-09 03:49:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2021-03-29 06:40:20 +00:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 15:18:46 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
2018-02-09 03:49:49 +00:00
|
|
|
*/
|
2018-12-26 06:06:24 +00:00
|
|
|
|
2019-12-27 21:19:28 +00:00
|
|
|
namespace Friendica\Module\Security;
|
2018-02-09 03:49:49 +00:00
|
|
|
|
2021-11-17 20:32:57 +00:00
|
|
|
use Friendica\App\BaseURL;
|
2018-02-09 03:49:49 +00:00
|
|
|
use Friendica\BaseModule;
|
2021-11-17 20:32:57 +00:00
|
|
|
use Friendica\Core\Cache\Capability\ICanCache;
|
2018-12-26 06:06:24 +00:00
|
|
|
use Friendica\Core\Hook;
|
2021-11-17 20:32:57 +00:00
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\Session\Capability\IHandleSessions;
|
2019-06-11 23:41:11 +00:00
|
|
|
use Friendica\Core\System;
|
|
|
|
use Friendica\Model\Profile;
|
2021-11-17 20:32:57 +00:00
|
|
|
use Friendica\Model\User\Cookie;
|
2021-01-19 04:32:48 +00:00
|
|
|
use Friendica\Security\TwoFactor;
|
2018-02-09 03:49:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logout module
|
|
|
|
*/
|
|
|
|
class Logout extends BaseModule
|
|
|
|
{
|
2021-11-17 20:32:57 +00:00
|
|
|
/** @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-09 03:49:49 +00:00
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Process logout requests
|
2018-02-09 03:49:49 +00:00
|
|
|
*/
|
2021-11-17 20:32:57 +00:00
|
|
|
public function rawContent()
|
2018-02-09 03:49:49 +00:00
|
|
|
{
|
2019-06-11 23:41:11 +00:00
|
|
|
$visitor_home = null;
|
|
|
|
if (remote_user()) {
|
|
|
|
$visitor_home = Profile::getMyURL();
|
2021-11-17 20:32:57 +00:00
|
|
|
$this->cache->delete('zrlInit:' . $visitor_home);
|
2019-06-11 23:41:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 06:06:24 +00:00
|
|
|
Hook::callAll("logging_out");
|
2021-01-19 04:32:48 +00:00
|
|
|
|
|
|
|
// Remove this trusted browser as it won't be able to be used ever again after the cookie is cleared
|
2021-11-17 20:32:57 +00:00
|
|
|
if ($this->cookie->get('trusted')) {
|
|
|
|
$this->trustedBrowserRepo->removeForUser(local_user(), $this->cookie->get('trusted'));
|
2021-01-19 04:32:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-17 20:32:57 +00:00
|
|
|
$this->cookie->clear();
|
|
|
|
$this->session->clear();
|
2019-06-11 23:41:11 +00:00
|
|
|
|
|
|
|
if ($visitor_home) {
|
|
|
|
System::externalRedirect($visitor_home);
|
|
|
|
} else {
|
2021-11-18 20:33:05 +00:00
|
|
|
info($this->t('Logged out.'));
|
2021-11-17 20:32:57 +00:00
|
|
|
$this->baseUrl->redirect();
|
2019-06-11 23:41:11 +00:00
|
|
|
}
|
2018-02-09 03:49:49 +00:00
|
|
|
}
|
|
|
|
}
|