Split login method into View and Action
This commit is contained in:
parent
ffeefd06c6
commit
8b8564309d
3 changed files with 11 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -1,33 +1,27 @@
|
|||
<?php
|
||||
class AuthController
|
||||
{
|
||||
public function loginAction()
|
||||
public function loginView()
|
||||
{
|
||||
$context = getContext();
|
||||
$context->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']));
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
{
|
||||
$registerNavItem(
|
||||
'Log in',
|
||||
\Chibi\Router::linkTo(['AuthController', 'loginAction']),
|
||||
\Chibi\Router::linkTo(['AuthController', 'loginView']),
|
||||
$activeController == 'auth' and $activeAction == 'login');
|
||||
|
||||
$registerNavItem(
|
||||
|
|
Loading…
Reference in a new issue