diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 5702c688..2884d34f 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -45,6 +45,11 @@ $context->simpleActionName = null; $context->simpleActionName); }); +\Chibi\Router::register(['AuthController', 'loginView'], 'GET', '/auth/login'); +\Chibi\Router::register(['AuthController', 'loginAction'], 'POST', '/auth/login'); +\Chibi\Router::register(['AuthController', 'logoutAction'], 'POST', '/auth/logout'); +\Chibi\Router::register(['AuthController', 'logoutAction'], 'GET', '/auth/logout'); + $postValidation = [ 'tag' => '[^\/]*', @@ -84,10 +89,6 @@ foreach (['GET', 'POST'] as $method) \Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}', ['name' => '[0-9a-zA-Z._-]+']); \Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}/{page}', ['name' => '[0-9a-zA-Z._-]+', 'page' => '\d*']); \Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}/{page}/{filter}', ['name' => '[0-9a-zA-Z._-]+', 'page' => '\d*', 'filter' => '.*']); - \Chibi\Router::register(['AuthController', 'loginAction'], $method, '/auth/login'); - \Chibi\Router::register(['AuthController', 'logoutAction'], $method, '/auth/logout'); - \Chibi\Router::register(['AuthController', 'loginAction'], 'POST', '/auth/login'); - \Chibi\Router::register(['AuthController', 'logoutAction'], 'POST', '/auth/logout'); \Chibi\Router::register(['PostController', 'uploadAction'], $method, '/posts/upload', $postValidation); \Chibi\Router::register(['PostController', 'toggleTagAction'], $method, '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation); diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index d6d8cfde..6e624c96 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -1,33 +1,27 @@ handleExceptions = true; //check if already logged in if (Auth::isLoggedIn()) - { self::redirectAfterLog(); - return; - } - - if (!InputHelper::get('submit')) - return; + } + public function loginAction() + { $suppliedName = InputHelper::get('name'); $suppliedPassword = InputHelper::get('password'); $remember = boolval(InputHelper::get('remember')); - $dbUser = Auth::login($suppliedName, $suppliedPassword, $remember); + Auth::login($suppliedName, $suppliedPassword, $remember); self::redirectAfterLog(); } public function logoutAction() { - $context = getContext(); - $context->viewName = null; - $context->layoutName = null; Auth::logout(); \Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction'])); } diff --git a/src/Views/top-navigation.phtml b/src/Views/top-navigation.phtml index 608555d3..80c8a4d8 100644 --- a/src/Views/top-navigation.phtml +++ b/src/Views/top-navigation.phtml @@ -64,7 +64,7 @@ { $registerNavItem( 'Log in', - \Chibi\Router::linkTo(['AuthController', 'loginAction']), + \Chibi\Router::linkTo(['AuthController', 'loginView']), $activeController == 'auth' and $activeAction == 'login'); $registerNavItem(