X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSecurity%2FAuthentication.php;h=d8d8ba4b424330eea6c00a549d96940a19057d43;hb=516018861e011865a902587876d484d6f0f42a66;hp=430ede13b4bc5e6eb6f1f8e6bf93601d1de1fec0;hpb=315dddbcb9232fea105d2da53ad2ba0e143bd7e4;p=friendica.git diff --git a/src/Security/Authentication.php b/src/Security/Authentication.php index 430ede13b4..d8d8ba4b42 100644 --- a/src/Security/Authentication.php +++ b/src/Security/Authentication.php @@ -23,10 +23,11 @@ namespace Friendica\Security; use Exception; use Friendica\App; -use Friendica\Core\Config\IConfig; -use Friendica\Core\PConfig\IPConfig; +use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Hook; use Friendica\Core\Session; +use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\System; use Friendica\Database\Database; use Friendica\Database\DBA; @@ -39,7 +40,6 @@ use Friendica\Util\Network; use Friendica\Util\Strings; use LightOpenID; use Friendica\Core\L10n; -use Friendica\Core\Logger; use Psr\Log\LoggerInterface; /** @@ -47,7 +47,7 @@ use Psr\Log\LoggerInterface; */ class Authentication { - /** @var IConfig */ + /** @var IManageConfigValues */ private $config; /** @var App\Mode */ private $mode; @@ -61,25 +61,25 @@ class Authentication private $logger; /** @var User\Cookie */ private $cookie; - /** @var Session\ISession */ + /** @var IHandleSessions */ private $session; - /** @var IPConfig */ + /** @var IManagePersonalConfigValues */ private $pConfig; /** * Authentication constructor. * - * @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 + * @param IManageConfigValues $config + * @param App\Mode $mode + * @param App\BaseURL $baseUrl + * @param L10n $l10n + * @param Database $dba + * @param LoggerInterface $logger + * @param User\Cookie $cookie + * @param IHandleSessions $session + * @param IManagePersonalConfigValues $pConfig */ - 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) + public function __construct(IManageConfigValues $config, App\Mode $mode, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, IHandleSessions $session, IManagePersonalConfigValues $pConfig) { $this->config = $config; $this->mode = $mode; @@ -142,9 +142,9 @@ class Authentication if ($this->session->get('authenticated')) { if ($this->session->get('visitor_id') && !$this->session->get('uid')) { - $contact = $this->dba->selectFirst('contact', [], ['id' => $this->session->get('visitor_id')]); + $contact = $this->dba->selectFirst('contact', ['id'], ['id' => $this->session->get('visitor_id')]); if ($this->dba->isResult($contact)) { - $a->contact = $contact; + $a->setContactId($contact['id']); } } @@ -306,34 +306,13 @@ class Authentication $this->session->set('new_member', time() < ($member_since + (60 * 60 * 24 * 14))); if (strlen($user_record['timezone'])) { - date_default_timezone_set($user_record['timezone']); - $a->timezone = $user_record['timezone']; + $a->setTimeZone($user_record['timezone']); } - $masterUid = $user_record['uid']; - - if ($this->session->get('submanage')) { - $user = $this->dba->selectFirst('user', ['uid'], ['uid' => $this->session->get('submanage')]); - if ($this->dba->isResult($user)) { - $masterUid = $user['uid']; - } - } - - $a->identities = User::identities($masterUid); - - if ($login_initial) { - $this->logger->info('auth_identities: ' . print_r($a->identities, true)); - } - - if ($login_refresh) { - $this->logger->info('auth_identities refresh: ' . print_r($a->identities, true)); - } - - $contact = $this->dba->selectFirst('contact', [], ['uid' => $user_record['uid'], 'self' => true]); + $contact = $this->dba->selectFirst('contact', ['id'], ['uid' => $user_record['uid'], 'self' => true]); if ($this->dba->isResult($contact)) { - $a->contact = $contact; - $a->cid = $contact['id']; - $this->session->set('cid', $a->cid); + $a->setContactId($contact['id']); + $this->session->set('cid', $contact['id']); } header('X-Account-Management-Status: active; name="' . $user_record['username'] . '"; id="' . $user_record['nickname'] . '"'); @@ -343,7 +322,7 @@ class Authentication // Set the login date for all identities of the user $this->dba->update('user', ['login_date' => DateTimeFormat::utcNow()], - ['parent-uid' => $masterUid, 'account_removed' => false]); + ['parent-uid' => $user_record['uid'], 'account_removed' => false]); } if ($login_initial) { @@ -363,7 +342,7 @@ class Authentication } } - $this->redirectForTwoFactorAuthentication($user_record['uid'], $a); + $this->redirectForTwoFactorAuthentication($user_record['uid']); if ($interactive) { if ($user_record['login_date'] <= DBA::NULL_DATETIME) { @@ -373,10 +352,11 @@ class Authentication } } - $a->user = $user_record; + $a->setLoggedInUserId($user_record['uid']); + $a->setLoggedInUserNickname($user_record['nickname']); if ($login_initial) { - Hook::callAll('logged_in', $a->user); + Hook::callAll('logged_in', $user_record); if (DI::module()->getName() !== 'home' && $this->session->exists('return_path')) { $this->baseUrl->redirect($this->session->get('return_path')); @@ -389,12 +369,11 @@ class Authentication * All return calls in this method skip two-factor authentication * * @param int $uid The User Identified - * @param App $a The Friendica Application context * * @throws HTTPException\ForbiddenException In case the two factor authentication is forbidden (e.g. for AJAX calls) * @throws HTTPException\InternalServerErrorException */ - private function redirectForTwoFactorAuthentication(int $uid, App $a) + private function redirectForTwoFactorAuthentication(int $uid) { // Check user setting, if 2FA disabled return if (!$this->pConfig->get($uid, '2fa', 'verified')) { @@ -402,7 +381,7 @@ class Authentication } // Check current path, if public or 2fa module return - if ($a->argc > 0 && in_array($a->argv[0], ['2fa', 'view', 'help', 'api', 'proxy', 'logout'])) { + if (DI::args()->getArgc() > 0 && in_array(DI::args()->getArgv()[0], ['2fa', 'view', 'help', 'api', 'proxy', 'logout'])) { return; }