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);
|
$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 =
|
$postValidation =
|
||||||
[
|
[
|
||||||
'tag' => '[^\/]*',
|
'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}', ['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}', ['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(['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', 'uploadAction'], $method, '/posts/upload', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'toggleTagAction'], $method, '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation);
|
\Chibi\Router::register(['PostController', 'toggleTagAction'], $method, '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation);
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
class AuthController
|
class AuthController
|
||||||
{
|
{
|
||||||
public function loginAction()
|
public function loginView()
|
||||||
{
|
{
|
||||||
$context = getContext();
|
$context = getContext();
|
||||||
$context->handleExceptions = true;
|
$context->handleExceptions = true;
|
||||||
|
|
||||||
//check if already logged in
|
//check if already logged in
|
||||||
if (Auth::isLoggedIn())
|
if (Auth::isLoggedIn())
|
||||||
{
|
|
||||||
self::redirectAfterLog();
|
self::redirectAfterLog();
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!InputHelper::get('submit'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
public function loginAction()
|
||||||
|
{
|
||||||
$suppliedName = InputHelper::get('name');
|
$suppliedName = InputHelper::get('name');
|
||||||
$suppliedPassword = InputHelper::get('password');
|
$suppliedPassword = InputHelper::get('password');
|
||||||
$remember = boolval(InputHelper::get('remember'));
|
$remember = boolval(InputHelper::get('remember'));
|
||||||
$dbUser = Auth::login($suppliedName, $suppliedPassword, $remember);
|
Auth::login($suppliedName, $suppliedPassword, $remember);
|
||||||
self::redirectAfterLog();
|
self::redirectAfterLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logoutAction()
|
public function logoutAction()
|
||||||
{
|
{
|
||||||
$context = getContext();
|
|
||||||
$context->viewName = null;
|
|
||||||
$context->layoutName = null;
|
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
|
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
{
|
{
|
||||||
$registerNavItem(
|
$registerNavItem(
|
||||||
'Log in',
|
'Log in',
|
||||||
\Chibi\Router::linkTo(['AuthController', 'loginAction']),
|
\Chibi\Router::linkTo(['AuthController', 'loginView']),
|
||||||
$activeController == 'auth' and $activeAction == 'login');
|
$activeController == 'auth' and $activeAction == 'login');
|
||||||
|
|
||||||
$registerNavItem(
|
$registerNavItem(
|
||||||
|
|
Loading…
Reference in a new issue