-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathSessionService.php
More file actions
61 lines (50 loc) · 1.5 KB
/
SessionService.php
File metadata and controls
61 lines (50 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Service;
use OCA\Libresign\AppInfo\Application;
use OCP\IAppConfig;
use OCP\ISession;
class SessionService {
public const NO_RENEWAL_INTERVAL = 0;
public const NO_MAXIMUM_VALIDITY = 0;
public function __construct(
protected ISession $session,
protected IAppConfig $appConfig,
) {
}
public function getSignStartTime(): int {
return $this->session->get('libresign-sign-start-time') ?? self::NO_RENEWAL_INTERVAL;
}
public function getSessionId(): string {
if ($this->isAuthenticated()) {
return $this->session->getId();
}
$uuid = $this->session->get('libresign-uuid');
if (is_string($uuid) && $uuid !== '') {
return $uuid;
}
return $this->session->getId();
}
public function setIdentifyMethodId(int $id): void {
$this->session->set('identify_method_id', $id);
}
public function getIdentifyMethodId(): ?int {
$id = $this->session->get('identify_method_id');
return $id;
}
public function resetDurationOfSignPage(): void {
$renewalInterval = $this->appConfig->getValueInt(Application::APP_ID, 'renewal_interval', self::NO_RENEWAL_INTERVAL);
if ($renewalInterval <= self::NO_RENEWAL_INTERVAL) {
return;
}
$this->session->reopen();
$this->session->set('libresign-sign-start-time', time());
}
public function isAuthenticated(): bool {
return $this->session->get('user_id') ? true : false;
}
}