szurubooru/src/Controllers/AuthController.php

53 lines
1.2 KiB
PHP
Raw Normal View History

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
{
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())
self::redirect();
}
2013-10-05 12:55:03 +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'));
Auth::login($suppliedName, $suppliedPassword, $remember);
self::redirect();
2013-10-05 12:55:03 +02:00
}
public function logoutAction()
{
2014-05-01 16:12:37 +02:00
Auth::logout();
self::redirect();
2013-10-05 12:55:03 +02: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
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']);
2014-05-03 23:27:00 +02:00
exit;
2014-05-01 16:12:37 +02:00
}
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']));
2014-05-03 23:27:00 +02:00
exit;
2014-05-01 16:12:37 +02:00
}
2013-10-05 12:55:03 +02:00
}