X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FAuthentication.php;h=106ba2a6021ccd542325b4c4bff87d6c477818ae;hb=9c12f3f226cefa64456c559fd060e067389d9886;hp=4d227c27109fbf2201999e1ca3db4b5774ffcc99;hpb=c6ce9ddaa41a59496cbe5cd93ace9bc552478ccd;p=friendica.git diff --git a/src/Core/Authentication.php b/src/Core/Authentication.php index 4d227c2710..106ba2a602 100644 --- a/src/Core/Authentication.php +++ b/src/Core/Authentication.php @@ -6,12 +6,8 @@ namespace Friendica\Core; use Friendica\BaseObject; -use Friendica\Core\Addon; -use Friendica\Core\Config; -use Friendica\Core\L10n; -use Friendica\Core\Logger; -use Friendica\Core\PConfig; use Friendica\Database\DBA; +use Friendica\Model\User; use Friendica\Util\DateTimeFormat; /** @@ -25,6 +21,7 @@ class Authentication extends BaseObject * @param array $user Record from "user" table * * @return string Hashed data + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function getCookieHashForUser($user) { @@ -36,8 +33,9 @@ class Authentication extends BaseObject /** * @brief Set the "Friendica" cookie * - * @param int $time + * @param int $time * @param array $user Record from "user" table + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function setCookie($time, $user = []) { @@ -59,12 +57,13 @@ class Authentication extends BaseObject /** * @brief Sets the provided user's authenticated session * - * @todo Should be moved to Friendica\Core\Session once it's created + * @todo Should be moved to Friendica\Core\Session once it's created * - * @param type $user_record - * @param type $login_initial - * @param type $interactive - * @param type $login_refresh + * @param array $user_record + * @param bool $login_initial + * @param bool $interactive + * @param bool $login_refresh + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function setAuthenticatedSessionForUser($user_record, $login_initial = false, $interactive = false, $login_refresh = false) { @@ -103,55 +102,16 @@ class Authentication extends BaseObject $a->timezone = $a->user['timezone']; } - $master_record = $a->user; + $masterUid = $user_record['uid']; - if ((x($_SESSION, 'submanage')) && intval($_SESSION['submanage'])) { - $user = DBA::selectFirst('user', [], ['uid' => $_SESSION['submanage']]); + if (!empty($_SESSION['submanage'])) { + $user = DBA::selectFirst('user', ['uid'], ['uid' => $_SESSION['submanage']]); if (DBA::isResult($user)) { - $master_record = $user; + $masterUid = $user['uid']; } } - if ($master_record['parent-uid'] == 0) { - // First add our own entry - $a->identities = [['uid' => $master_record['uid'], - 'username' => $master_record['username'], - 'nickname' => $master_record['nickname']]]; - - // Then add all the children - $r = DBA::select('user', ['uid', 'username', 'nickname'], - ['parent-uid' => $master_record['uid'], 'account_removed' => false]); - if (DBA::isResult($r)) { - $a->identities = array_merge($a->identities, DBA::toArray($r)); - } - } else { - // Just ensure that the array is always defined - $a->identities = []; - - // First entry is our parent - $r = DBA::select('user', ['uid', 'username', 'nickname'], - ['uid' => $master_record['parent-uid'], 'account_removed' => false]); - if (DBA::isResult($r)) { - $a->identities = DBA::toArray($r); - } - - // Then add all siblings - $r = DBA::select('user', ['uid', 'username', 'nickname'], - ['parent-uid' => $master_record['parent-uid'], 'account_removed' => false]); - if (DBA::isResult($r)) { - $a->identities = array_merge($a->identities, DBA::toArray($r)); - } - } - - $r = DBA::p("SELECT `user`.`uid`, `user`.`username`, `user`.`nickname` - FROM `manage` - INNER JOIN `user` ON `manage`.`mid` = `user`.`uid` - WHERE `user`.`account_removed` = 0 AND `manage`.`uid` = ?", - $master_record['uid'] - ); - if (DBA::isResult($r)) { - $a->identities = array_merge($a->identities, DBA::toArray($r)); - } + $a->identities = User::identities($masterUid); if ($login_initial) { Logger::log('auth_identities: ' . print_r($a->identities, true), Logger::DEBUG); @@ -174,7 +134,7 @@ class Authentication extends BaseObject // Set the login date for all identities of the user DBA::update('user', ['login_date' => DateTimeFormat::utcNow()], - ['parent-uid' => $master_record['uid'], 'account_removed' => false]); + ['parent-uid' => $masterUid, 'account_removed' => false]); } if ($login_initial) { @@ -192,7 +152,7 @@ class Authentication extends BaseObject } if ($login_initial) { - Addon::callHooks('logged_in', $a->user); + Hook::callAll('logged_in', $a->user); if (($a->module !== 'home') && isset($_SESSION['return_path'])) { $a->internalRedirect($_SESSION['return_path']);