Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Jun 30, 2022
1 parent fca4317 commit 5b045fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/Application/User/Service/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public function login(string $password, bool $rememberMe) : void
setcookie(self::AUTHENTICATION_COOKIE_NAME, $token, (int)$expirationDate->format('U'));
}

public function logout() : void
{
$token = filter_input(INPUT_COOKIE, 'id');

if ($token !== null) {
$this->deleteToken($token);
unset($_COOKIE[self::AUTHENTICATION_COOKIE_NAME]);
setcookie(self::AUTHENTICATION_COOKIE_NAME, '', -1);
}

session_regenerate_id();
}

private function createExpirationDate(int $days = 1) : DateTime
{
$timestamp = strtotime('+' . $days . ' day');
Expand Down
10 changes: 1 addition & 9 deletions src/HttpController/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ public function login(Request $request) : Response

public function logout() : Response
{
session_regenerate_id();

$token = filter_input(INPUT_COOKIE, 'id');

if ($token !== null) {
$this->authenticationService->deleteToken($token);
unset($_COOKIE['id']);
setcookie('id', '', -1);
}
$this->authenticationService->logout();

return Response::create(
StatusCode::createSeeOther(),
Expand Down

0 comments on commit 5b045fd

Please sign in to comment.