]> git.mxchange.org Git - friendica.git/blobdiff - src/App/Authentication.php
Only display redundant preview data with preview picture
[friendica.git] / src / App / Authentication.php
index 39c684ffd37143061e8c81c4fca8aeb299a5fd62..e3d273747029b452226a9a017737706984af64f8 100644 (file)
@@ -1,16 +1,31 @@
 <?php
-
 /**
- * @file /src/Core/Authentication.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @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\App;
 
 use Exception;
 use Friendica\App;
-use Friendica\Core\Config\IConfiguration;
+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;
@@ -22,7 +37,7 @@ 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;
 
 /**
@@ -30,7 +45,7 @@ use Psr\Log\LoggerInterface;
  */
 class Authentication
 {
-       /** @var IConfiguration */
+       /** @var IConfig */
        private $config;
        /** @var App\Mode */
        private $mode;
@@ -46,33 +61,37 @@ class Authentication
        private $cookie;
        /** @var Session\ISession */
        private $session;
+       /** @var IPConfig */
+       private $pConfig;
 
        /**
         * Authentication constructor.
         *
-        * @param IConfiguration   $config
-        * @param App\Mode        $mode
-        * @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(IConfiguration $config, App\Mode $mode, 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->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
         *
@@ -188,7 +207,7 @@ class Authentication
 
                // if it's an email address or doesn't resolve to a URL, fail.
                if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) {
-                       notice($this->l10n->t('Login failed.') . EOL);
+                       notice($this->l10n->t('Login failed.'));
                        $this->baseUrl->redirect();
                }
 
@@ -251,7 +270,7 @@ class Authentication
                        }
                } catch (Exception $e) {
                        $this->logger->warning('authenticate: failed login attempt', ['action' => 'login', 'username' => Strings::escapeTags($username), 'ip' => $_SERVER['REMOTE_ADDR']]);
-                       info($this->l10n->t('Login failed. Please check your credentials.' . EOL));
+                       notice($this->l10n->t('Login failed. Please check your credentials.'));
                        $this->baseUrl->redirect();
                }
 
@@ -279,7 +298,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
@@ -295,7 +314,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'],
@@ -369,9 +388,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');
-                       } else {
-                               info($this->l10n->t("Welcome back %s", $user_record['username']));
+                               $this->baseUrl->redirect('settings/profile/photo/new');
                        }
                }
 
@@ -395,7 +412,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;
                }