Ejemplo n.º 1
0
 /**
  * @throws \PSFS\base\exception\FormException
  * @throws \PSFS\base\exception\RouterException
  */
 public function __construct()
 {
     $this->init();
     $this->setAction($this->router->getRoute('admin-module'))->setAttrs(array());
     $this->add('module', array('label' => _('Nombre del Módulo')))->add('force', array('label' => _('Sobreescribir ficheros'), 'type' => 'select', 'data' => array(_('No'), _('Sí')), 'required' => false))->add('is_module', array('label' => _('Es un módulo de PSFS'), 'type' => 'select', 'data' => array(_('No'), _('Sí')), 'required' => false))->add('controllerType', array('label' => _('Tipo de controlador'), 'type' => 'select', 'data' => array("" => _("Normal"), "Auth" => _("Requiere autenticación de usuario"), "AuthAdmin" => _("Requiere autenticación de administrador")), 'required' => false));
     $data = Security::getInstance()->getAdmins();
     //Aplicamos estilo al formulario
     $this->setAttrs(array('class' => 'col-md-6'));
     //Hidratamos el formulario
     $this->setData($data);
     //Añadimos las acciones del formulario
     $this->addButton('submit', 'Generar');
 }
Ejemplo n.º 2
0
 /**
  * Method that convert an exception to html
  *
  * @param \Exception $e
  *
  * @return string HTML
  */
 protected function dumpException(\Exception $e)
 {
     Logger::log('Starting dump exception');
     $ex = NULL !== $e->getPrevious() ? $e->getPrevious() : $e;
     $error = array("error" => $ex->getMessage(), "file" => $ex->getFile(), "line" => $ex->getLine());
     Logger::log('Throwing exception', LOG_ERR, $error);
     unset($error);
     return $this->router->httpNotFound($ex);
 }
Ejemplo n.º 3
0
 /**
  * @throws \PSFS\base\exception\RouterException
  */
 public function __construct()
 {
     $this->setAction(Router::getInstance()->getRoute('admin-setup'));
     $this->add('username', array('label' => _('User Alias'), 'autocomplete' => 'off'))->add('password', array('type' => 'password', 'label' => _('Password'), 'autocomplete' => 'off'))->add('profile', array('type' => 'select', 'label' => _("Role"), 'value' => sha1('superadmin'), 'autocomplete' => 'off', 'data' => Security::getProfiles()));
     //Apply styling to the form
     $this->setAttrs(array("class" => "col-md-6", "autocomplete" => "off"));
     //Add action buttons to form
     $this->addButton('submit');
 }
Ejemplo n.º 4
0
 /**
  * Función que devuelve una url correspondiente a una ruta
  * @param string $path
  * @param bool|FALSE $absolute
  * @param array $params
  *
  * @return string|null
  */
 public static function route($path = '', $absolute = false, array $params = null)
 {
     $router = Router::getInstance();
     try {
         return $router->getRoute($path, $absolute, $params);
     } catch (\Exception $e) {
         return $router->getRoute('', $absolute, $params);
     }
 }
Ejemplo n.º 5
0
 /**
  * Extract the foreign relation field
  * @param ColumnMap $mappedColumn
  * @param $field
  * @return Field
  */
 public static function extractForeignModelsField(ColumnMap $mappedColumn, $field)
 {
     $fDto = new Field($field, _($field));
     $fDto->type = Field::COMBO_TYPE;
     $fDto->required = $mappedColumn->isNotNull();
     $relatedModel = strtolower($mappedColumn->getRelation()->getForeignTable()->getPhpName());
     $fDto->entity = $relatedModel;
     $fDto->url = Router::getInstance()->getRoute('api-' . $relatedModel . '-pk');
     return $fDto;
 }
Ejemplo n.º 6
0
 /**
  * Basic test for Router functionality
  */
 public function testRouter()
 {
     $router = Router::getInstance();
     // Is ROuter instance?
     $this->assertTrue($router instanceof Router);
     // Check if route file exists
     $this->assertFileExists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json");
     // CHecks if we have admin routes as minimal routes
     $adminRoutes = $router->getAdminRoutes();
     $this->assertNotEmpty($adminRoutes);
     $this->assertArrayHasKey("superadmin", $adminRoutes);
 }
Ejemplo n.º 7
0
 /**
  * Service to regenerate routes
  * @GET
  * @route /admin/routes/gen
  * @visible false
  * @return string HTML
  */
 public function regenerateUrls()
 {
     $router = Router::getInstance();
     try {
         $router->hydrateRouting();
         $router->simpatize();
         Security::getInstance()->setFlash("callback_message", _("Rutas generadas correctamente"));
         Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-routes", true));
     } catch (\Exception $e) {
         Logger::log($e->getMessage(), LOG_ERR);
         Security::getInstance()->setFlash("callback_message", _("Algo no ha salido bien, revisa los logs"));
         Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-routes", true));
     }
     return $this->redirect('admin-routes');
 }
Ejemplo n.º 8
0
 /**
  * Servicio que guarda la configuración de la plataforma
  * @POST
  * @route /admin/config
  * @visible false
  * @return string
  * @throws \HttpException
  */
 public function saveConfig()
 {
     Logger::getInstance()->infoLog(_("Guardando configuración"));
     /* @var $form \PSFS\base\config\ConfigForm */
     $form = new ConfigForm(Router::getInstance()->getRoute('admin-config'), Config::$required, Config::$optional, Config::getInstance()->dumpConfig());
     $form->build();
     $form->hydrate();
     if ($form->isValid()) {
         $debug = Config::getInstance()->getDebugMode();
         $newDebug = $form->getFieldValue("debug");
         if (Config::save($form->getData(), $form->getExtraData())) {
             Logger::log(_('Configuración guardada correctamente'));
             //Verificamos si tenemos que limpiar la cache del DocumentRoot
             if (boolval($debug) !== boolval($newDebug)) {
                 Config::clearDocumentRoot();
             }
             Security::getInstance()->setFlash("callback_message", _("Configuración actualizada correctamente"));
             Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-config", true));
         } else {
             throw new \HttpException(_('Error al guardar la configuración, prueba a cambiar los permisos'), 403);
         }
     }
     return $this->render('welcome.html.twig', array('text' => _("Bienvenido a PSFS"), 'config' => $form, 'typeahead_data' => array_merge(Config::$required, Config::$optional)));
 }
Ejemplo n.º 9
0
 /**
  * Constructor por defecto
  * @throws \PSFS\base\exception\RouterException
  */
 public function __construct()
 {
     $this->setAction(Router::getInstance()->getRoute('admin-login'));
     $this->add("user", array("label" => _("Usuario"), "required" => true, "pattern" => Form::VALID_ALPHANUMERIC, "ng-model" => "username"))->add("pass", array("label" => _("Contraseña"), "required" => true, "type" => "password"))->add(Form::SEPARATOR)->add("route", array("required" => false, "type" => "hidden"))->addButton('submit', _("Acceder como {{username}}"))->addButton("cancel", _("Cancelar"), "button", array("onclick" => "javacript:location.href = \"" . Router::getInstance()->getRoute('') . "\";", "class" => "btn-link"));
 }
Ejemplo n.º 10
0
Archivo: Admin.php Proyecto: c15k0/psfs
 /**
  * Wrapper de asignación de los menus
  * @return array
  */
 protected function getMenu()
 {
     return Router::getInstance()->getAdminRoutes();
 }
Ejemplo n.º 11
0
 /**
  * Método que devuelve los dominios de una plataforma
  * @param bool $append
  * @return array
  */
 public static function getDomains($append = false)
 {
     $domains = Router::getInstance()->getDomains();
     if ($append) {
         foreach ($domains as &$domain) {
             foreach ($domain as &$path) {
                 $path .= DIRECTORY_SEPARATOR;
             }
         }
     }
     return $domains;
 }
Ejemplo n.º 12
0
 /**
  * @param string $route
  * @return null|string
  */
 public static function checkDefaultRoute($route)
 {
     $default = null;
     if (FALSE !== preg_match('/\\/$/', $route)) {
         $default = Config::getInstance()->get('home_action');
     } elseif (false !== preg_match('/admin/', $route)) {
         $default = Config::getInstance()->get('admin_action') ?: 'admin-login';
     }
     if (null !== $default) {
         return Router::getInstance()->execute(Router::getInstance()->getRoute($default));
     }
     return null;
 }
Ejemplo n.º 13
0
 /**
  * Wrapper para obtener la url de una ruta interna
  * @param string $route
  * @param bool $absolute
  * @param array $params
  * @return string|null
  * @throws RouterException
  */
 public function getRoute($route = '', $absolute = false, array $params = array())
 {
     return Router::getInstance()->getRoute($route, $absolute, $params);
 }