]> git.mxchange.org Git - friendica.git/blobdiff - src/App/Authentication.php
Merge pull request #8226 from nupplaphil/bug/wait_for_conn
[friendica.git] / src / App / Authentication.php
index b1424e0fd63ea9e3ea9377c0790341712ad0c9d3..2e1a823c71d2e9fb60b6fd282248ee563db4cab8 100644 (file)
@@ -8,20 +8,21 @@ namespace Friendica\App;
 
 use Exception;
 use Friendica\App;
-use Friendica\Core\Config\Configuration;
+use Friendica\Core\Config\IConfig;
+use Friendica\Core\PConfig\IPConfig;
 use Friendica\Core\Hook;
-use Friendica\Core\PConfig;
 use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\User;
 use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use LightOpenID;
-use Friendica\Core\L10n\L10n;
+use Friendica\Core\L10n;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -29,8 +30,10 @@ use Psr\Log\LoggerInterface;
  */
 class Authentication
 {
-       /** @var Configuration */
+       /** @var IConfig */
        private $config;
+       /** @var App\Mode */
+       private $mode;
        /** @var App\BaseURL */
        private $baseUrl;
        /** @var L10n */
@@ -43,31 +46,37 @@ class Authentication
        private $cookie;
        /** @var Session\ISession */
        private $session;
+       /** @var IPConfig */
+       private $pConfig;
 
        /**
         * Authentication constructor.
         *
-        * @param Configuration   $config
-        * @param App\BaseURL     $baseUrl
-        * @param L10n            $l10n
-        * @param Database        $dba
-        * @param LoggerInterface $logger
-        * @param User\Cookie     $cookie
+        * @param IConfig          $config
+        * @param App\Mode         $mode
+        * @param App\BaseURL      $baseUrl
+        * @param L10n             $l10n
+        * @param Database         $dba
+        * @param LoggerInterface  $logger
+        * @param User\Cookie      $cookie
         * @param Session\ISession $session
+        * @param IPConfig         $pConfig
         */
-       public function __construct(Configuration $config, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, Session\ISession $session)
+       public function __construct(IConfig $config, App\Mode $mode, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, Session\ISession $session, IPConfig $pConfig)
        {
                $this->config  = $config;
+               $this->mode    = $mode;
                $this->baseUrl = $baseUrl;
                $this->l10n    = $l10n;
                $this->dba     = $dba;
                $this->logger  = $logger;
-               $this->cookie = $cookie;
+               $this->cookie  = $cookie;
                $this->session = $session;
+               $this->pConfig = $pConfig;
        }
 
        /**
-        * @brief Tries to auth the user from the cookie or session
+        * Tries to auth the user from the cookie or session
         *
         * @param App   $a      The Friendica Application context
         *
@@ -97,7 +106,8 @@ class Authentication
                                        $user['password'] ?? '',
                                        $user['prvkey'] ?? '')) {
                                        $this->logger->notice("Hash doesn't fit.", ['user' => $data->uid]);
-                                       $this->session->delete();
+                                       $this->session->clear();
+                                       $this->cookie->clear();
                                        $this->baseUrl->redirect();
                                }
 
@@ -132,7 +142,7 @@ class Authentication
                                                        'addr'        => $this->session->get('addr'),
                                                        'remote_addr' => $_SERVER['REMOTE_ADDR']]
                                        );
-                                       $this->session->delete();
+                                       $this->session->clear();
                                        $this->baseUrl->redirect();
                                }
 
@@ -148,7 +158,7 @@ class Authentication
                                        ]
                                );
                                if (!$this->dba->isResult($user)) {
-                                       $this->session->delete();
+                                       $this->session->clear();
                                        $this->baseUrl->redirect();
                                }
 
@@ -273,7 +283,7 @@ class Authentication
        }
 
        /**
-        * @brief Sets the provided user's authenticated session
+        * Sets the provided user's authenticated session
         *
         * @param App   $a           The Friendica application context
         * @param array $user_record The current "user" record
@@ -289,7 +299,7 @@ class Authentication
                $this->session->setMultiple([
                        'uid'           => $user_record['uid'],
                        'theme'         => $user_record['theme'],
-                       'mobile-theme'  => PConfig::get($user_record['uid'], 'system', 'mobile_theme'),
+                       'mobile-theme'  => $this->pConfig->get($user_record['uid'], 'system', 'mobile_theme'),
                        'authenticated' => 1,
                        'page_flags'    => $user_record['page-flags'],
                        'my_url'        => $this->baseUrl->get() . '/profile/' . $user_record['nickname'],
@@ -363,7 +373,7 @@ class Authentication
                        if ($user_record['login_date'] <= DBA::NULL_DATETIME) {
                                info($this->l10n->t('Welcome %s', $user_record['username']));
                                info($this->l10n->t('Please upload a profile photo.'));
-                               $this->baseUrl->redirect('profile_photo/new');
+                               $this->baseUrl->redirect('settings/profile/photo/new');
                        } else {
                                info($this->l10n->t("Welcome back %s", $user_record['username']));
                        }
@@ -374,7 +384,7 @@ class Authentication
                if ($login_initial) {
                        Hook::callAll('logged_in', $a->user);
 
-                       if ($a->module !== 'home' && $this->session->exists('return_path')) {
+                       if (DI::module()->getName() !== 'home' && $this->session->exists('return_path')) {
                                $this->baseUrl->redirect($this->session->get('return_path'));
                        }
                }
@@ -389,7 +399,7 @@ class Authentication
        private function twoFactorCheck(int $uid, App $a)
        {
                // Check user setting, if 2FA disabled return
-               if (!PConfig::get($uid, '2fa', 'verified')) {
+               if (!$this->pConfig->get($uid, '2fa', 'verified')) {
                        return;
                }
 
@@ -404,10 +414,10 @@ class Authentication
                }
 
                // Case 2: No valid 2FA session: redirect to code verification page
-               if ($a->isAjax()) {
+               if ($this->mode->isAjax()) {
                        throw new HTTPException\ForbiddenException();
                } else {
-                       $a->internalRedirect('2fa');
+                       $this->baseUrl->redirect('2fa');
                }
        }
 }