Esempio n. 1
0
File: Admin.php Progetto: c15k0/psfs
 /**
  * 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));
     }
 }
Esempio n. 2
0
 /**
  * Servicio que busca el path para un dominio dado
  * @param $string
  * @param string $file_path
  *
  * @return string
  */
 public static function findDomainPath($string, $file_path)
 {
     $domains = Template::getDomains(TRUE);
     $filename_path = null;
     if (!file_exists($file_path) && 0 < count($domains)) {
         foreach ($domains as $domain => $paths) {
             $domain_filename = str_replace($domain, $paths["public"], $string);
             if (file_exists($domain_filename)) {
                 $filename_path = $domain_filename;
                 continue;
             }
         }
     }
     return $filename_path;
 }
Esempio n. 3
0
 /**
  * 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);
     }
 }
Esempio n. 4
0
 /**
  * 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);
 }
Esempio n. 5
0
 /**
  * Función que copia un recurso directamente en el DocumentRoot
  * @param string $path
  * @param string $dest
  * @param bool|FALSE $force
  *
  * @return string
  * @throws ConfigException
  */
 public static function resource($path, $dest, $force = false)
 {
     $debug = Config::getInstance()->getDebugMode();
     $domains = Template::getDomains(true);
     $filename_path = self::extractPathname($path, $domains);
     GeneratorService::copyResources($dest, $force, $filename_path, $debug);
     return '';
 }
Esempio n. 6
0
 /**
  * Método que añade la ruta del controlador a los path de plantillas Twig
  * @param string $path
  * @return $this
  */
 protected function setTemplatePath($path)
 {
     $this->tpl->addPath($path, $this->domain);
     return $this;
 }
Esempio n. 7
0
 /**
  * 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));
 }
Esempio n. 8
0
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);
});