2013-10-05 12:55:03 +02:00
|
|
|
<?php
|
2013-10-05 21:24:20 +02:00
|
|
|
class AuthController
|
2013-10-05 12:55:03 +02:00
|
|
|
{
|
2014-05-02 22:18:20 +02:00
|
|
|
public function loginView()
|
2013-10-05 12:55:03 +02:00
|
|
|
{
|
2014-04-29 21:35:29 +02:00
|
|
|
$context = getContext();
|
|
|
|
$context->handleExceptions = true;
|
2013-10-05 21:22:28 +02:00
|
|
|
|
2013-10-05 12:55:03 +02:00
|
|
|
//check if already logged in
|
2014-05-01 16:12:37 +02:00
|
|
|
if (Auth::isLoggedIn())
|
2014-05-02 22:19:08 +02:00
|
|
|
self::redirect();
|
2014-05-02 22:18:20 +02:00
|
|
|
}
|
2013-10-05 12:55:03 +02:00
|
|
|
|
2014-05-02 22:18:20 +02:00
|
|
|
public function loginAction()
|
|
|
|
{
|
2014-04-30 08:08:24 +02:00
|
|
|
$suppliedName = InputHelper::get('name');
|
|
|
|
$suppliedPassword = InputHelper::get('password');
|
2014-05-01 16:12:37 +02:00
|
|
|
$remember = boolval(InputHelper::get('remember'));
|
2014-05-02 22:18:20 +02:00
|
|
|
Auth::login($suppliedName, $suppliedPassword, $remember);
|
2014-05-02 22:19:08 +02:00
|
|
|
self::redirect();
|
2013-10-05 12:55:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function logoutAction()
|
|
|
|
{
|
2014-05-01 16:12:37 +02:00
|
|
|
Auth::logout();
|
2014-05-02 22:19:08 +02:00
|
|
|
self::redirect();
|
2013-10-05 12:55:03 +02:00
|
|
|
}
|
2013-10-27 20:39:32 +01:00
|
|
|
|
2013-10-30 23:24:27 +01:00
|
|
|
public static function observeWorkFinish()
|
|
|
|
{
|
2014-04-29 21:35:29 +02:00
|
|
|
if (strpos(\Chibi\Util\Headers::get('Content-Type'), 'text/html') === false)
|
2013-10-30 23:24:27 +01:00
|
|
|
return;
|
2014-04-29 21:35:29 +02:00
|
|
|
if (\Chibi\Util\Headers::getCode() != 200)
|
|
|
|
return;
|
|
|
|
$context = getContext();
|
|
|
|
if ($context->simpleControllerName == 'auth')
|
2013-10-30 23:24:27 +01:00
|
|
|
return;
|
|
|
|
$_SESSION['login-redirect-url'] = $context->query;
|
|
|
|
}
|
2014-05-01 16:12:37 +02:00
|
|
|
|
2014-05-02 22:19:08 +02:00
|
|
|
private static function redirect()
|
2014-05-01 16:12:37 +02:00
|
|
|
{
|
|
|
|
if (isset($_SESSION['login-redirect-url']))
|
|
|
|
{
|
|
|
|
\Chibi\Util\Url::forward(\Chibi\Util\Url::makeAbsolute($_SESSION['login-redirect-url']));
|
|
|
|
unset($_SESSION['login-redirect-url']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
|
|
|
|
}
|
2013-10-05 12:55:03 +02:00
|
|
|
}
|