2024-07-15 20:46:44 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* @author Sascha Nitsch (grumpydeveloper)
|
|
|
|
**/
|
|
|
|
|
|
|
|
namespace Federator\DIO;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IO functions related to users
|
|
|
|
*/
|
|
|
|
class User
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* extend the given user with internal data
|
|
|
|
* @param \mysqli $dbh database handle @unused-param
|
|
|
|
* @param \Federator\Data\User $user user to extend @unused-param
|
|
|
|
*/
|
|
|
|
protected static function extendUser(\mysqli $dbh, \Federator\Data\User $user) : void
|
|
|
|
{
|
|
|
|
// do nothing for now
|
|
|
|
// TODO: if a new user, create own database entry with additionally needed info
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get User by session id
|
|
|
|
*
|
|
|
|
* @param \mysqli $dbh
|
|
|
|
* database handle
|
|
|
|
* @param string $_session
|
|
|
|
* session
|
|
|
|
* @param string $_user
|
|
|
|
* user/profile name
|
2024-07-17 21:45:33 +02:00
|
|
|
* @param \Federator\Connector\Connector $connector
|
2024-07-15 20:46:44 +02:00
|
|
|
* connector to fetch use with
|
2024-07-17 21:45:33 +02:00
|
|
|
* @param \Federator\Cache\Cache|null $cache
|
2024-07-15 20:46:44 +02:00
|
|
|
* optional caching service
|
2024-07-17 21:45:33 +02:00
|
|
|
* @return \Federator\Data\User|false
|
2024-07-15 20:46:44 +02:00
|
|
|
*/
|
|
|
|
public static function getUserBySession($dbh, $_session, $_user, $connector, $cache)
|
|
|
|
{
|
2024-07-17 21:45:33 +02:00
|
|
|
$saveToCache = false;
|
2024-07-15 20:46:44 +02:00
|
|
|
$user = false;
|
2024-07-17 21:45:33 +02:00
|
|
|
if ($cache !== null) {
|
2024-07-15 20:46:44 +02:00
|
|
|
$user = $cache->getRemoteUserBySession($_session, $_user);
|
|
|
|
}
|
|
|
|
|
2024-07-17 21:45:33 +02:00
|
|
|
if ($user === false) {
|
|
|
|
// ask connector for user-id
|
|
|
|
$user = $connector->getRemoteUserBySession($_session, $_user);
|
|
|
|
$saveToCache = true;
|
|
|
|
}
|
2024-07-15 20:46:44 +02:00
|
|
|
if ($user === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-07-17 21:45:33 +02:00
|
|
|
self::extendUser($dbh, $user);
|
|
|
|
if ($cache !== null && $saveToCache) {
|
2024-07-15 20:46:44 +02:00
|
|
|
$cache->saveRemoteUserBySession($_session, $_user, $user);
|
|
|
|
}
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
}
|