diff --git a/src/Application/User/Service/Authentication.php b/src/Application/User/Service/Authentication.php index df757a3c..f9159033 100644 --- a/src/Application/User/Service/Authentication.php +++ b/src/Application/User/Service/Authentication.php @@ -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'); diff --git a/src/HttpController/AuthenticationController.php b/src/HttpController/AuthenticationController.php index 868a9cfb..7639bd14 100644 --- a/src/HttpController/AuthenticationController.php +++ b/src/HttpController/AuthenticationController.php @@ -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(),