/** * 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)); } }
/** * 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); }