public function index() { if (!empty(AuthenticationHandler::$data)) { Go::to('a'); } $f = new Form('search'); $this->addForm('search', $f); $this->setTitle('Savely.co'); $this->addScript('Dabox'); $this->addScript('Request'); $this->addScript('StageChart'); $form_register = new Form('register'); if ($form_register->isValid()) { $values = $form_register->getValues(); } $this->addForm('register', $form_register); $form = new Form('login'); if ($form->isValid()) { $values = $form->getValues(); if (AuthenticationHandler::setUserSession($values['login'], $values['password'])) { Go::to('a'); } else { $this->addContent('login_error', Dictionary::term('login.error.unknown_user')); } } $m = new ModelLink(); $all = $m->retrieveLinksHome(); $this->addContent('products', $all); $this->addForm('login', $form); }
public function index() { $this->addScript('Dabox'); $this->addScript('Request'); $this->addScript('M4Tween'); $this->addScript('StageChart'); $this->setTitle('feed - Savely.co'); $f = new Form('addEntry'); if ($f->isValid()) { $values = $f->getValues(); $url = $values['url']; $this->model_link->addState($url, AuthenticationHandler::$data['id_user']); } $this->addContent('user_links', $this->model_link->retrieveLinksByUser(AuthenticationHandler::$data['id_user'])); }
public function password() { $this->setTitle('Change your password - Savely.co'); $f = new Form('password'); if ($f->isValid()) { $v = $f->getValues(); if (ModelAuthentication::getInstance()->changePassword($v['currentPassword'], $v['newPassword'])) { AuthenticationHandler::unsetUserSession(); AuthenticationHandler::setUserSession(ModelAuthentication::getInstance()->getLogin(), $v['newPassword']); $this->addContent('confirmation', 'New Password Saved'); } else { $this->addContent('error', 'You current password does not match'); } } else { $this->addContent('error', $f->getError()); } $this->addForm('password', $f); }
public function share() { Autoload::addComponent("Achilles.share"); $this->setTitle("Submit a link"); /** @var AuthenticationHandler $auth */ $auth = Application::getInstance()->authenticationHandler; if (!$auth::is(AuthenticationHandler::USER)) { Go::to404(); } $m = new ModelPost(); $form = new Form("post_share"); if ($form->isValid()) { $v = $form->getValues(); $insertedPermalink = $m->share($v); Header::location('post/' . $insertedPermalink); } else { $this->addContent("error", $form->getError()); } $this->addForm("share", $form); }
public function sign_in() { $this->setTitle("Sign in"); //todo redirect if logged $authHandler = Application::getInstance()->authenticationHandler; $f = new Form('signin'); if ($f->isValid()) { $data = $f->getValues(); $authHandlerInst = call_user_func_array(array($authHandler, 'getInstance'), array()); if ($authHandlerInst->setUserSession($data["login_user"], $data["password_user"])) { Go::to(); } else { Logs::write("Tentative de connexion au front <" . $data["login_user"] . ":" . $data["password_user"] . ">", Logs::WARNING); $this->addContent("error", "Le login ou le mot de passe est incorrect"); } } else { trace("aaaah"); trace($f->getError()); $this->addContent('error', $f->getError()); } $this->addForm('sign_in', $f); }
/** * @return void */ public function autocomplete() { $datas = null; $response = array("error" => ""); if (!isset($_GET["form_name"]) || empty($_GET["form_name"])) { $response["error"] = '$_GET["form_name"] require'; } if (!isset($_GET["input_name"]) || empty($_GET["input_name"])) { $response["error"] = '$_GET["input_name"] require'; } if (empty($response["error"])) { $path_to_form = "includes/applications/" . $_GET["application"] . "/modules/"; if ($_GET["module"]) { $path_to_form .= $_GET["module"] . "/"; } else { $path_to_form .= "front/"; } $path_to_form .= "forms/form." . $_GET["form_name"] . ".json"; try { $datas = SimpleJSON::import($path_to_form); } catch (Exception $e) { $response["error"] = "Formulaire introuvable " . $path_to_form; $this->response($response); } if (!is_array($datas[$_GET["input_name"]])) { $response["error"] = "Champs ciblé introuvable"; $this->response($response); } $input = $datas[$_GET["input_name"]]; if ($input["tag"] != Form::TAG_INPUT || $input["attributes"]["type"] != "text") { $response["error"] = "Champs ciblé n'est pas un input type 'text'"; $this->response($response); } if (!$input["autoComplete"] || !is_array($input["autoComplete"])) { $response["error"] = "Les éléments de bases ne sont pas renseignés"; $this->response($response); } $model = new $input["autoComplete"]["model"](); $cond = Query::condition()->andWhere($input["autoComplete"]["value"], Query::LIKE, "%" . $_GET["q"] . "%"); if (isset($input["autoComplete"]["condition"]) && is_array($input["autoComplete"]["condition"]) && count($input["autoComplete"]["condition"])) { foreach ($input["autoComplete"]["condition"] as $m => $p) { call_user_func_array(array($cond, $m), $p); } } if (isset($_GET["replies"]) && Form::isNumeric($_GET["replies"])) { $result = $model->{$input}["autoComplete"]["method"]($_GET["replies"]); } else { $result = $model->{$input}["autoComplete"]["method"]($cond, $input["autoComplete"]["value"]); } $response["responses"] = array(); foreach ($result as $r) { $d = array("value" => $r[$input["autoComplete"]["value"]]); if (isset($input["autoComplete"]["raw"]) && is_array($input["autoComplete"]["raw"])) { foreach ($input["autoComplete"]["raw"] as $v) { $d[$v] = $r[$v]; } } $response["responses"][] = $d; } } $this->response($response); }
private static function upload($pName, $pId, $pData, $pRequire = "") { self::$ct_upload++; $file = $style = $value = ""; $server_url = Configuration::$server_url; /** * @todo concaténer la valeur du relative path de l'application en cours à $server_url ? */ $disabled = isset($pData["attributes"]["disabled"]) && $pData["attributes"]["disabled"] == "disabled" ? "disabled" : ""; if (isset($pData["attributes"]["value"]) && !empty($pData["attributes"]["value"])) { $value = $pData["attributes"]["value"]; $file = $server_url; /** @var ModelUpload $m */ $m = isset($pData["model"]) && !empty($pData["model"]) ? $pData["model"] : "core\\models\\ModelUpload"; if (Form::isNumeric($value)) { $file .= Application::getInstance()->getPathPart() . $m::getPathById($value); } else { $file .= $value; } } $deleteFileAction = ""; if (isset($pData['deleteFileAction']) && !empty($pData['deleteFileAction'])) { if ($value && Form::isNumeric($value)) { $action = preg_replace('/\\{id\\}/', $value, $pData['deleteFileAction']); } else { $action = $pData['deleteFileAction']; } $deleteFileAction = 'data-delete_file_action="' . $action . '"'; } $comp = "<input " . $disabled . " type='file' name='" . $pName . "_input' data-form_name='" . $pData["form_name"] . "' data-input_name='" . $pData["field_name"] . "' data-application='" . Core::$application . "' data-value='" . $value . "' data-file='" . $file . "' data-module='" . Core::$module . "'" . $deleteFileAction . ">"; $input = self::getLabel($pData["label"] . $pRequire, $pId); $input .= self::getComponent($comp, 'upload'); return $input; }
/** * Méthode de modification d'une entrée * Récupère les données via le model et les injecte dans le formulaire * @return boolean */ public function edit() { if (!$this->actions->isEnabled('edit')) { Go::to404(); } $this->setTitle($this->titles->get('edit')); try { $form = new Form($this->formName); } catch (Exception $e) { $form = new Form($this->formName, false); $inputs = $this->model->generateInputsFromDescribe(); foreach ($inputs as $nam => $inp) { $form->setInput($nam, $inp); } } $data = $this->model->getTupleById($_GET["id"]); if (!$data) { Go::to($this->className); } $form->injectValues($data); if ($form->isValid()) { if ($this->model->updateById($_GET["id"], $form->getValues())) { $this->addContent("confirmation", Dictionary::term("backoffice.forms.editDone")); $this->dispatchEvent(new Event(self::EVENT_SUCCESSFUL_EDIT)); } else { $this->addContent("error", Dictionary::term("backoffice.forms.errorSQL")); $this->dispatchEvent(new Event(self::EVENT_FAILED_EDIT)); } $id = $_GET["id"]; $form->setUploadFileName($id); } else { $this->addContent("error", $form->getError()); } $this->setTemplate("default", "form"); $this->addContent("id", $this->model->id); $this->addForm("instance", $form); $this->addContent("h1", $this->h1->get('edit')); }
/** * Méthode d'ajout d'un formulaire envoyé à la vue * @param String $pName Nom d'accès au formulaire * @param Form $pForm * @return void */ protected function addForm($pName, Form &$pForm) { $pForm->prepareToView(); $this->forms[$pName] = $pForm; }