2018-02-09 03:49:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, 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-20 14:38:03 +00:00
|
|
|
use Friendica\App;
|
2018-02-09 03:49:49 +00:00
|
|
|
use Friendica\BaseModule;
|
2021-11-19 19:18:48 +00:00
|
|
|
use Friendica\Core\Cache\Capability\ICanCache;
|
2018-12-26 06:06:24 +00:00
|
|
|
use Friendica\Core\Hook;
|
2021-11-19 19:18:48 +00:00
|
|
|
use Friendica\Core\L10n;
|
2022-10-23 18:41:17 +00:00
|
|
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
2019-06-11 23:41:11 +00:00
|
|
|
use Friendica\Core\System;
|
2022-10-17 18:55:22 +00:00
|
|
|
use Friendica\DI;
|
2019-06-11 23:41:11 +00:00
|
|
|
use Friendica\Model\Profile;
|
2021-11-19 19:18:48 +00:00
|
|
|
use Friendica\Model\User\Cookie;
|
2021-11-21 19:06:36 +00:00
|
|
|
use Friendica\Module\Response;
|
2021-11-20 14:38:03 +00:00
|
|
|
use Friendica\Util\Profiler;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2018-02-09 03:49:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logout module
|
|
|
|
*/
|
|
|
|
class Logout extends BaseModule
|
|
|
|
{
|
2021-11-19 19:18:48 +00:00
|
|
|
/** @var ICanCache */
|
|
|
|
protected $cache;
|
|
|
|
/** @var Cookie */
|
|
|
|
protected $cookie;
|
2022-10-25 06:07:42 +00:00
|
|
|
/** @var IHandleUserSessions */
|
2021-11-19 19:18:48 +00:00
|
|
|
protected $session;
|
|
|
|
|
2022-10-23 18:41:17 +00:00
|
|
|
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, ICanCache $cache, Cookie $cookie, IHandleUserSessions $session, array $server, array $parameters = [])
|
2021-11-19 19:18:48 +00:00
|
|
|
{
|
2021-11-21 19:06:36 +00:00
|
|
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
2021-11-19 19:18:48 +00:00
|
|
|
|
2022-06-25 12:45:33 +00:00
|
|
|
$this->cache = $cache;
|
|
|
|
$this->cookie = $cookie;
|
|
|
|
$this->session = $session;
|
2021-11-19 19:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-20 14:38:03 +00:00
|
|
|
protected function rawContent(array $request = [])
|
2018-02-09 03:49:49 +00:00
|
|
|
{
|
2019-06-11 23:41:11 +00:00
|
|
|
$visitor_home = null;
|
2022-10-23 18:41:17 +00:00
|
|
|
if ($this->session->getRemoteUserId()) {
|
2019-06-11 23:41:11 +00:00
|
|
|
$visitor_home = Profile::getMyURL();
|
2021-11-19 19:18:48 +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
|
|
|
|
2022-06-25 12:45:33 +00:00
|
|
|
// If this is a trusted browser, redirect to the 2fa signout page
|
|
|
|
if ($this->cookie->get('2fa_cookie_hash')) {
|
|
|
|
$this->baseUrl->redirect('2fa/signout');
|
2021-01-19 04:32:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 19:18:48 +00:00
|
|
|
$this->cookie->clear();
|
|
|
|
$this->session->clear();
|
2019-06-11 23:41:11 +00:00
|
|
|
|
|
|
|
if ($visitor_home) {
|
|
|
|
System::externalRedirect($visitor_home);
|
|
|
|
} else {
|
2022-10-17 18:55:22 +00:00
|
|
|
DI::sysmsg()->addInfo($this->t('Logged out.'));
|
2021-11-19 19:18:48 +00:00
|
|
|
$this->baseUrl->redirect();
|
2019-06-11 23:41:11 +00:00
|
|
|
}
|
2018-02-09 03:49:49 +00:00
|
|
|
}
|
|
|
|
}
|