/** * Método estático de login de administrador * @param string $route * @return string HTML * @throws \PSFS\base\exception\FormException */ public static function staticAdminLogon($route = null) { if ('login' !== Config::getInstance()->get('admin_login')) { return AdminServices::getInstance()->setAdminHeaders(); } else { $form = new LoginForm(); $form->setData(array("route" => $route)); $form->build(); $tpl = Template::getInstance(); $tpl->setPublicZone(true); return $tpl->render("login.html.twig", array('form' => $form)); } }
/** * Método que ejecuta una acción del framework y revisa si lo tenemos cacheado ya o no * * @param string $route * @param array|null $action * @param types\Controller $class * @param array $params */ protected function executeCachedRoute($route, $action, $class, $params = NULL) { Logger::log('Executing route ' . $route, LOG_INFO); Security::getInstance()->setSessionKey("__CACHE__", $action); $cache = Cache::needCache(); $execute = TRUE; if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { $cacheDataName = $this->cache->getRequestCacheHash(); $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, $cache, function () { }); if (NULL !== $cachedData) { $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", $cache, function () { }, Cache::JSON); Template::getInstance()->renderCache($cachedData, $headers); $execute = FALSE; } } if ($execute) { call_user_func_array(array($class, $action['method']), $params); } }
/** * Servicio que valida el login * @param null $route * @POST * @visible false * @route /admin/login * @return string * @throws \PSFS\base\exception\FormException */ public function postLogin($route = null) { $form = new LoginForm(); $form->setData(array("route" => $route)); $form->build(); $tpl = Template::getInstance(); $tpl->setPublicZone(true); $template = "login.html.twig"; $params = array('form' => $form); $cookies = array(); $form->hydrate(); if ($form->isValid()) { if (Security::getInstance()->checkAdmin($form->getFieldValue("user"), $form->getFieldValue("pass"))) { $cookies = array(array("name" => Security::getInstance()->getHash(), "value" => base64_encode($form->getFieldValue("user") . ":" . $form->getFieldValue("pass")), "expire" => time() + 3600, "http" => true)); $template = "redirect.html.twig"; $params = array('route' => $form->getFieldValue("route"), 'status_message' => _("Acceso permitido... redirigiendo!!"), 'delay' => 1); } else { $form->setError("user", _("El usuario no tiene acceso a la web")); } } return $tpl->render($template, $params, $cookies); }
/** * Función que deveulve un formulario en html * @param Form $form */ public static function form(Form $form) { Template::getInstance()->getTemplateEngine()->display('forms/base.html.twig', array('form' => $form)); }
/** * Servicio que devuelve una pantalla de error porque se necesita estar authenticado * * @param string|null $route * * @return string|null */ public function notAuthorized($route) { return Template::getInstance()->render('notauthorized.html.twig', array('route' => $route)); }
if (!isset($console)) { $console = new Application(); } $console->register('psfs:create:root')->setDefinition(array(new InputArgument('path', InputArgument::OPTIONAL, 'Path en el que crear el Document Root')))->setDescription('Comando de creación del Document Root del projecto')->setCode(function (InputInterface $input, OutputInterface $output) { // Creates the html path $path = $input->getArgument('path'); if (empty($path)) { $path = WEB_DIR; } \PSFS\base\config\Config::createDir($path); $paths = array("js", "css", "img", "media", "font"); foreach ($paths as $htmlPath) { \PSFS\base\config\Config::createDir($path . DIRECTORY_SEPARATOR . $htmlPath); } // Generates the root needed files $files = ['_' => '_.php', 'browserconfig' => 'browserconfig.xml', 'crossdomain' => 'crossdomain.xml', 'humans' => 'humans.txt', 'robots' => 'robots.txt']; foreach ($files as $templates => $filename) { $text = \PSFS\base\Template::getInstance()->dump("generator/html/" . $templates . '.html.twig'); if (false === file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $text)) { $output->writeln('Can\\t create the file ' . $filename); } else { $output->writeln($filename . ' created successfully'); } } //Export base locale translations if (!file_exists(BASE_DIR . DIRECTORY_SEPARATOR . 'locale')) { \PSFS\base\config\Config::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); \PSFS\Services\GeneratorService::copyr(SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'locale', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); } $output->writeln("Document root generado en " . $path); });