Authentificacion
This commit is contained in:
@ -18,6 +18,12 @@ class Login {
|
||||
$container->get('urls.base'),
|
||||
'admin'
|
||||
]))
|
||||
->withStatus(301);
|
||||
->withStatus(302);
|
||||
}
|
||||
public function logout(Request $request, Response $response, Service $login, Container $container): Response {
|
||||
$login->logout();
|
||||
return $response
|
||||
->withHeader('Location', $container->get('urls.base'))
|
||||
->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class Auth {
|
||||
$response = $handler->handle($request);
|
||||
|
||||
$is_logged_in = $this->login->checkAuth($request);
|
||||
if (!$is_logged_in and $request->getRequestTarget() != $this->login_url) {
|
||||
if (!$is_logged_in and $request->getRequestTarget() != $this->login_url and $request->getRequestTarget() != implode('/', [dirname($this->login_url), 'logout'])) {
|
||||
return $response
|
||||
->withHeader('Location', $this->login_url)
|
||||
->withStatus(301);
|
||||
|
@ -108,4 +108,15 @@ class Login {
|
||||
$this->is_logged_in = true;
|
||||
return true;
|
||||
}
|
||||
public function logout(): bool {
|
||||
$this->removeCookie();
|
||||
$data = [
|
||||
'ip' => 0,
|
||||
'token' => ':',
|
||||
'time' => 0
|
||||
];
|
||||
$this->manager->folder('data')->save($this->filename, $data);
|
||||
$this->is_logged_in = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user