]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Security/Logout.php
Remove the activity
[friendica.git] / src / Module / Security / Logout.php
index 062d55687b4f81a82d6dea0e478b81f218a6f9bd..528dd295e7592eaa6834de89149cbd5b0114d103 100644 (file)
@@ -1,45 +1,88 @@
 <?php
 /**
- * @file src/Module/Logout.php
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @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/>.
+ *
  */
 
 namespace Friendica\Module\Security;
 
+use Friendica\App;
 use Friendica\BaseModule;
-use Friendica\App\Authentication;
-use Friendica\Core\Cache;
+use Friendica\Core\Cache\Capability\ICanCache;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
-use Friendica\Core\Session;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\System;
+use Friendica\DI;
 use Friendica\Model\Profile;
+use Friendica\Model\User\Cookie;
+use Friendica\Module\Response;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Logout module
- *
- * @author Hypolite Petovan <hypolite@mrpetovan.com>
  */
 class Logout extends BaseModule
 {
+       /** @var ICanCache */
+       protected $cache;
+       /** @var Cookie */
+       protected $cookie;
+       /** @var IHandleUserSessions */
+       protected $session;
+
+       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 = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->cache   = $cache;
+               $this->cookie  = $cookie;
+               $this->session = $session;
+       }
+
+
        /**
-        * @brief Process logout requests
+        * Process logout requests
         */
-       public static function init(array $parameters = [])
+       protected function rawContent(array $request = [])
        {
                $visitor_home = null;
-               if (remote_user()) {
+               if ($this->session->getRemoteUserId()) {
                        $visitor_home = Profile::getMyURL();
-                       Cache::delete('zrlInit:' . $visitor_home);
+                       $this->cache->delete('zrlInit:' . $visitor_home);
                }
 
                Hook::callAll("logging_out");
-               Session::clear();
+
+               // If this is a trusted browser, redirect to the 2fa signout page
+               if ($this->cookie->get('2fa_cookie_hash')) {
+                       $this->baseUrl->redirect('2fa/signout');
+               }
+
+               $this->cookie->clear();
+               $this->session->clear();
 
                if ($visitor_home) {
                        System::externalRedirect($visitor_home);
                } else {
-                       info(L10n::t('Logged out.'));
-                       self::getApp()->internalRedirect();
+                       DI::sysmsg()->addInfo($this->t('Logged out.'));
+                       $this->baseUrl->redirect();
                }
        }
 }