Skip to content

Commit

Permalink
Make fields private
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamwin committed Jan 12, 2021
1 parent 242e2d3 commit ab93cae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 19 additions & 3 deletions src/User.php
Expand Up @@ -25,13 +25,13 @@ class User
* remaining inactive. If this property is not set, the user will be logged out after
* the current session expires.
*/
public ?int $authTimeout = null;
private ?int $authTimeout = null;

/**
* @var int|null the number of seconds in which the user will be logged out automatically
* regardless of activity.
*/
public ?int $absoluteAuthTimeout = null;
private ?int $absoluteAuthTimeout = null;

private IdentityRepositoryInterface $identityRepository;
private EventDispatcherInterface $eventDispatcher;
Expand Down Expand Up @@ -315,7 +315,9 @@ private function renewAuthStatus(): void

if (!($identity instanceof GuestIdentity) && ($this->authTimeout !== null || $this->absoluteAuthTimeout !== null)) {
$expire = $this->authTimeout !== null ? $this->session->get(self::SESSION_AUTH_EXPIRE) : null;
$expireAbsolute = $this->absoluteAuthTimeout !== null ? $this->session->get(self::SESSION_AUTH_ABSOLUTE_EXPIRE) : null;
$expireAbsolute = $this->absoluteAuthTimeout !== null
? $this->session->get(self::SESSION_AUTH_ABSOLUTE_EXPIRE)
: null;
if (($expire !== null && $expire < time()) || ($expireAbsolute !== null && $expireAbsolute < time())) {
$this->logout(false);
} elseif ($this->authTimeout !== null) {
Expand Down Expand Up @@ -346,4 +348,18 @@ public function can(string $permissionName, array $params = []): bool

return $this->accessChecker->userHasPermission($this->getId(), $permissionName, $params);
}

public function setAuthTimeout(int $timeout = null): self
{
$this->authTimeout = $timeout;

return $this;
}

public function setAbsoluteAuthTimeout(int $timeout = null): self
{
$this->absoluteAuthTimeout = $timeout;

return $this;
}
}
12 changes: 6 additions & 6 deletions tests/UserTest.php
Expand Up @@ -75,7 +75,7 @@ public function testGetIdentityReturnsGuestIfSessionHasExpiredAuthTimeout(): voi
$sessionStorage
);

$user->authTimeout = 60;
$user->setAuthTimeout(60);

$this->assertInstanceOf(GuestIdentity::class, $user->getIdentity());
}
Expand All @@ -99,7 +99,7 @@ public function testGetIdentityReturnsGuestIfSessionHasExpiredAbsoluteAuthTimeou
$sessionStorage
);

$user->absoluteAuthTimeout = 60;
$user->setAbsoluteAuthTimeout(60);

$this->assertInstanceOf(GuestIdentity::class, $user->getIdentity());
}
Expand All @@ -125,7 +125,7 @@ public function testGetIdentityReturnsCorrectValueAndSetAuthExpire(): void
$sessionStorage = $this->createSessionStorage(['__auth_id' => 'test-id']);
$user = new User($repository, $this->createDispatcher(), $sessionStorage);

$user->authTimeout = 60;
$user->setAuthTimeout(60);

$this->assertEquals('test-id', $user->getIdentity()->getId());
$this->assertTrue($sessionStorage->has('__auth_expire'));
Expand Down Expand Up @@ -307,8 +307,8 @@ public function testSwitchIdentity(): void
$sessionStorage
);

$user->authTimeout = 60;
$user->absoluteAuthTimeout = 3600;
$user->setAuthTimeout(60);
$user->setAbsoluteAuthTimeout(3600);

$user->setIdentity($this->createIdentity('test-id'));
$user->switchIdentity($this->createIdentity('test-id-2'));
Expand All @@ -327,7 +327,7 @@ public function testSwitchIdentityToGuest(): void
$this->createDispatcher()
);

$user->authTimeout = 60;
$user->setAuthTimeout(60);

$user->setIdentity($this->createIdentity('test-id'));
$user->switchIdentity(new GuestIdentity());
Expand Down

0 comments on commit ab93cae

Please sign in to comment.