namespace Friendica\Core;
use Friendica\BaseObject;
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
use Friendica\Database\DBA;
+use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
/**
* @param array $user Record from "user" table
*
* @return string Hashed data
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getCookieHashForUser($user)
{
/**
* @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 = [])
{
/**
* @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)
{
$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('auth_identities: ' . print_r($a->identities, true), LOGGER_DEBUG);
+ Logger::log('auth_identities: ' . print_r($a->identities, true), Logger::DEBUG);
}
if ($login_refresh) {
- logger('auth_identities refresh: ' . print_r($a->identities, true), LOGGER_DEBUG);
+ Logger::log('auth_identities refresh: ' . print_r($a->identities, true), Logger::DEBUG);
}
$contact = DBA::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => true]);
// 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) {
* The week ensures that sessions will expire after some inactivity.
*/
if (!empty($_SESSION['remember'])) {
- logger('Injecting cookie for remembered user ' . $a->user['nickname']);
+ Logger::log('Injecting cookie for remembered user ' . $a->user['nickname']);
self::setCookie(604800, $user_record);
unset($_SESSION['remember']);
}
}
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']);