. */ namespace SP\Modules\Web\Controllers; use SP\Controller\ControllerBase; use SP\Core\SessionFactory; use SP\Core\SessionUtil; use SP\Html\Html; use SP\Http\Response; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Services\Auth\LoginService; use SP\Util\Json; /** * Class LoginController * * @package SP\Modules\Web\Controllers */ class LoginController extends ControllerBase { /** * Login action * * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @throws \ReflectionException */ public function loginAction() { $loginService = new LoginService($this->config, $this->session, $this->theme, $this->eventDispatcher); Json::returnJson($loginService->doLogin()); } /** * Logout action * * @throws \SP\Core\Dic\ContainerException * @throws \ReflectionException */ public function logoutAction() { if ($this->session->isLoggedIn()) { // $inactiveTime = abs(round((time() - SessionFactory::getLastActivity()) / 60, 2)); // $totalTime = abs(round((time() - SessionFactory::getStartActivity()) / 60, 2)); // $Log = new Log(); // $LogMessage = $Log->getLogMessage(); // $LogMessage->setAction(__u('Finalizar sesión')); // $LogMessage->addDetails(__u('Usuario'), SessionFactory::getUserData()->getLogin()); // $LogMessage->addDetails(__u('Tiempo inactivo'), $inactiveTime . ' min.'); // $LogMessage->addDetails(__u('Tiempo total'), $totalTime . ' min.'); // $Log->writeLog(); SessionUtil::cleanSession(); SessionFactory::setLoggedOut(true); $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); $layoutHelper->getCustomLayout('logout', 'logout'); $this->view(); } else { Response::redirect('index.php?r=login'); } } /** * Index action * * @throws \SP\Core\Dic\ContainerException * @throws \ReflectionException */ public function indexAction() { $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher); $layoutHelper->getCustomLayout('index', 'login'); if (SessionFactory::getLoggedOut() === true) { SessionFactory::setLoggedOut(); $this->view->assign('loggedOut', 1); } else { $this->view->assign('loggedOut', 0); } $this->view->assign('mailEnabled', $this->configData->isMailEnabled()); $this->view->assign('updated', SessionFactory::getAppUpdated()); SessionFactory::setAppUpdated(false); $getParams = []; // Comprobar y parsear los parámetros GET para pasarlos como POST en los inputs if (count($_GET) > 0) { foreach ($_GET as $param => $value) { $getParams['g_' . Html::sanitizeFull($param)] = Html::sanitizeFull($value); } } $this->view->assign('getParams', $getParams); $this->view(); } }