Skip to content

Commit 70fe8aa

Browse files
committed
User: logout reason is cached
1 parent 91d6bd3 commit 70fe8aa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Security/User.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class User
5959
/** @var bool|null */
6060
private $authenticated;
6161

62+
/** @var int|null */
63+
private $logoutReason;
64+
6265

6366
public function __construct(
6467
IUserStorage $storage,
@@ -98,6 +101,7 @@ public function login($user, string $password = null): void
98101
$this->storage->setAuthenticated(true);
99102
$this->identity = $user;
100103
$this->authenticated = true;
104+
$this->logoutReason = null;
101105
$this->onLoggedIn($this);
102106
}
103107

@@ -111,6 +115,7 @@ final public function logout(bool $clearIdentity = false): void
111115
$this->onLoggedOut($this);
112116
$this->storage->setAuthenticated(false);
113117
$this->authenticated = false;
118+
$this->logoutReason = self::MANUAL;
114119
}
115120
if ($clearIdentity) {
116121
$this->storage->setIdentity(null);
@@ -147,6 +152,7 @@ private function getStoredData(): void
147152
{
148153
$this->authenticated = $this->storage->isAuthenticated();
149154
$this->identity = $this->storage->getIdentity();
155+
$this->logoutReason = $this->storage->getLogoutReason();
150156
}
151157

152158

@@ -163,7 +169,7 @@ public function getId()
163169

164170
final public function refreshStorage(): void
165171
{
166-
$this->identity = $this->authenticated = null;
172+
$this->identity = $this->authenticated = $this->logoutReason = null;
167173
}
168174

169175

@@ -239,7 +245,7 @@ public function setExpiration($expire, /*int*/$flags = 0)
239245
*/
240246
final public function getLogoutReason(): ?int
241247
{
242-
return $this->storage->getLogoutReason();
248+
return $this->logoutReason;
243249
}
244250

245251

tests/Security/MockUserStorage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ public function setExpiration(?string $time, int $flags = 0)
4040

4141
public function getLogoutReason(): ?int
4242
{
43+
return null;
4344
}
4445
}

0 commit comments

Comments
 (0)