Skip to content

Commit 059c79b

Browse files
committed
Implement logout
1 parent b2c8d63 commit 059c79b

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

controllers/SiteController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use app\core\Application;
1212
use app\core\Controller;
1313
use app\core\Request;
14+
use app\core\Response;
1415
use app\models\LoginForm;
1516
use app\models\User;
1617

@@ -63,6 +64,12 @@ public function register(Request $request)
6364
]);
6465
}
6566

67+
public function logout(Request $request, Response $response)
68+
{
69+
Application::$app->logout();
70+
$response->redirect('/');
71+
}
72+
6673
public function contact()
6774
{
6875
return $this->render('contact');

core/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function resolve()
5252
Application::$app->controller = $controller;
5353
$callback[0] = $controller;
5454
}
55-
return call_user_func($callback, $this->request);
55+
return call_user_func($callback, $this->request, $this->response);
5656
}
5757

5858
public function renderView($view, $params = [])

core/Session.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function get($key)
5151
return $_SESSION[$key] ?? false;
5252
}
5353

54+
public function remove($key)
55+
{
56+
unset($_SESSION[$key]);
57+
}
58+
5459
public function __destruct()
5560
{
5661
$this->removeFlashMessages();

public/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
$app->router->post('/register', [SiteController::class, 'register']);
3030
$app->router->get('/login', [SiteController::class, 'login']);
3131
$app->router->post('/login', [SiteController::class, 'login']);
32+
$app->router->get('/logout', [SiteController::class, 'logout']);
3233
$app->router->get('/contact', [SiteController::class, 'contact']);
3334
$app->router->get('/about', [AboutController::class, 'index']);
3435

0 commit comments

Comments
 (0)