19declare(strict_types=1);
25use Psr\Http\Message\ResponseInterface;
44 public function handle(): ResponseInterface
51 if ($this->token_cipher ===
null) {
52 $this->
logger->warning(
'Session reminder call without encryption key, please run the ILIAS setup (update).');
53 $response[
'message'] =
'ILIAS could not decrypt the session reminder token.';
57 $token = $this->
http->wrapper()->post()->retrieve(
60 $this->refinery->kindlyTo()->string(),
61 $this->refinery->always(
'')
66 $token_data =
$token !==
'' ? $this->token_cipher->decode(
$token) :
null;
67 if ($token_data ===
null || $token_data[
'user_id'] <= 0) {
68 $this->
logger->debug(
'Session reminder call with missing or invalid token');
69 $response[
'message'] =
'ILIAS could not decrypt the session reminder token.';
74 $hash = $token_data[
'session_hash'];
76 $this->
logger->debug(
'Session reminder call for user ' .
$user_id .
' and session id hash: ' . $hash);
79 $res = $this->db->queryF(
80 'SELECT usess.session_id, usess.expires, usess.user_id, od.create_date ' .
81 'FROM usr_session usess ' .
82 'INNER JOIN object_data od ON od.obj_id = usess.user_id ' .
83 'WHERE usess.user_id = %s',
89 while ($row = $this->db->fetchAssoc(
$res)) {
98 if (hash_equals($row_hash, $hash)) {
103 if ($matches === []) {
104 $response[
'message'] =
'ILIAS could not determine the session data.';
108 if (count($matches) > 1) {
109 $response[
'message'] =
'The determined session data is not unique.';
115 $response[
'message'] =
'ILIAS could not fetch the session data or the corresponding user is no more authenticated.';
119 $expiration_time =
$data[
'expires'];
120 if ($expiration_time ===
null) {
121 $response[
'message'] =
'ILIAS could not determine the expiration time from the session data.';
124 $expiration_time = (
int)
$data[
'expires'];
127 $response[
'message'] =
'The session is already expired. The client should have received a remind command before.';
134 $response[
'message'] =
'ILIAS could not fetch the session data or the corresponding user is no more authenticated.';
143 $reminder_time = $expiration_time - ($session_reminder->getEffectiveLeadTime() * 60);
144 if ($reminder_time > $this->clock->now()->getTimestamp()) {
146 $response[
'message'] =
'Lead time not reached, yet. Current time: ' .
147 date(
'Y-m-d H:i:s') .
', Reminder time: ' .
date(
'Y-m-d H:i:s', $reminder_time);
152 switch ($ilUser->getTimeFormat()) {
154 $formatted_expiration_time = $dateTime->get(
IL_CAL_FKT_DATE,
'g:ia', $ilUser->getTimeZone());
159 $formatted_expiration_time = $dateTime->get(
IL_CAL_FKT_DATE,
'H:i', $ilUser->getTimeZone());
164 'extend_url' =>
'./ilias.php?baseClass=' . ilDashboardGUI::class,
165 'txt' => str_replace(
169 $this->
lng->txt(
'session_reminder_alert'),
171 $formatted_expiration_time,
187 return $this->
http->response()
188 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
189 ->withBody(Streams::ofString(json_encode(
$data, JSON_THROW_ON_ERROR)));
194 return $expirationTime < $this->clock->now()->getTimestamp();
201 isset(
$data[
'user_id']) &&
202 (
int)
$data[
'user_id'] > 0 &&
Encodes the opaque token the session reminder sends to sessioncheck.php.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
@classDescription Date and time handling
INI file parser — compatibility wrapper.
Component logger with individual log levels by component id.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
isAuthenticatedUsrSession(?array $data)
__construct(private GlobalHttpState $http, private Refinery $refinery, private ilLanguage $lng, private ilDBInterface $db, private ilIniFile $client_ini, private ilLogger $logger, private ClockInterface $clock, private ilSetting $settings, private ?TokenCipher $token_cipher)
isSessionAlreadyExpired(int $expirationTime)
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
Interface GlobalHttpState.
readonly HttpService $http
static http()
Fetches the global http state from ILIAS.
foreach($_POST as $key=> $value) $res