Skip to content

Commit

Permalink
Fix breaking error
Browse files Browse the repository at this point in the history
  • Loading branch information
JVT038 committed Nov 30, 2024
1 parent aa9a7e4 commit 2bd71c5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Domain/User/Service/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createAuthenticationObjectFromCookie() : ?AuthenticationObject
{
$token = filter_input(INPUT_COOKIE, self::AUTHENTICATION_COOKIE_NAME);
$authenticationMethod = AuthenticationObject::COOKIE_AUTHENTICATION;
if (empty($token) === true || $this->isValidToken((string)$token) === true) {
if (empty($token) === true || $this->isValidToken((string)$token) === false) {
unset($_COOKIE[self::AUTHENTICATION_COOKIE_NAME]);
setcookie(self::AUTHENTICATION_COOKIE_NAME, '', -1);
return null;
Expand Down Expand Up @@ -145,9 +145,10 @@ public function getCurrentUserId() : int
throw new RuntimeException('Could not find a current user');
}
$this->sessionWrapper->set('userId', $authenticationObject->getUser()->getId());
$userId = $authenticationObject->getUser()->getId();
}

if ($userId === null) {
if ($userId == null) {
throw new RuntimeException('Could not find a current user');
}
return $userId;
Expand Down Expand Up @@ -200,12 +201,16 @@ public function isUserPageVisibleForWebRequest(UserEntity $targetUser) : bool
return $this->isUserPageVisibleForUser($targetUser, $requestUserId);
}

public function isValidAuthToken(string $token) : bool
public function isValidToken(string $token) : bool
{
$tokenExpirationDate = $this->repository->findAuthTokenExpirationDate($token);

if ($tokenExpirationDate === null || $tokenExpirationDate->isAfter(DateTime::create()) === false) {
if ($tokenExpirationDate !== null) {
if ($tokenExpirationDate === null) {
if($this->repository->findUserByApiToken($token) === null) {
return false;
}
} else {
if($tokenExpirationDate->isAfter(DateTime::create()) === false) {
$this->repository->deleteAuthToken($token);
return false;
}
Expand Down

0 comments on commit 2bd71c5

Please sign in to comment.