public function executeUpdate(\core\HTTPRequest $request) { $this->page()->addVar('title', 'Modifier les identifiants de connexion'); $this->_addBreadcrumb(); $configData = $this->config->read(); $this->page()->addVar('username', $configData['username']); if ($request->postExists('login-password')) { $password = $request->postData('login-password'); if ($this->_hashPassword($password) == $configData['password']) { $configData['username'] = $request->postData('login-update-username'); $newPassword = $request->postData('login-update-password'); if (!empty($newPassword)) { $configData['password'] = $this->_hashPassword($newPassword); } try { $this->config->write($configData); } catch (\Exception $e) { $this->page()->addVar('error', $e->getMessage()); return; } $this->page()->addVar('updated?', true); } else { $this->page()->addVar('error', 'Incorrect password'); } } }
public function executeInsertRoute(\core\HTTPRequest $request) { $this->page()->addVar('title', 'Ajouter une route'); $this->_addBreadcrumb(); if ($request->postExists('route-url')) { $routeApp = $request->postData('route-app'); $routeVarsList = $request->postData('route-vars'); $routeVars = explode(',', $routeVarsList); foreach ($routeVars as $i => $var) { $routeVars[$i] = trim($var); } $route = array('url' => $request->postData('route-url'), 'module' => $request->postData('route-module'), 'action' => $request->postData('route-action'), 'vars' => $routeVars); $this->page()->addVar('route', $route); $this->page()->addVar('routeApp', $routeApp); $this->page()->addVar('routeVarsList', $routeVarsList); $configPath = __DIR__ . '/../../../etc/app/' . $routeApp . '/routes.json'; try { $conf = new \core\Config($configPath); $routes = $conf->read(); $routes[] = $route; $conf->write($routes); } catch (\Exception $e) { $this->page()->addVar('error', $e->getMessage()); return; } $this->page()->addVar('inserted?', true); } }
public function executeIndex(\core\HTTPRequest $request) { $captcha = \lib\Captcha::build(); $this->page()->addVar('captcha', $captcha); if ($request->postExists('message-sender-name')) { $messageData = array('senderName' => trim($request->postData('message-sender-name')), 'senderEmail' => $request->postData('message-sender-email'), 'subject' => trim($request->postData('message-subject')), 'content' => trim($request->postData('message-content'))); $this->page()->addVar('message', $messageData); try { $message = new \lib\entities\ContactMessage($messageData); } catch (\InvalidArgumentException $e) { $this->page()->addVar('error', $e->getMessage()); return; } $captchaId = (int) $request->postData('captcha-id'); $captchaValue = (int) $request->postData('captcha-value'); $captcha = \lib\Captcha::get($captchaId); if (empty($captcha)) { $this->page()->addVar('error', 'Your session has expired. Please try again'); return; } if (!$captcha->check($captchaValue)) { $this->page()->addVar('error', 'Invalid captcha'); return; } $contactConfig = $this->config->read(); $messageDest = $contactConfig['email']; $messageSubject = $contactConfig['subjectPrepend'] . ' ' . $message['subject']; $messageContent = 'Nom : ' . $message['senderName'] . ' <' . $message['senderEmail'] . '>' . "\n"; $messageContent .= 'Sujet : ' . $message['subject'] . "\n"; $messageContent .= 'Message :' . "\n" . $message['content']; $messageHeaders = 'From: ' . $message['senderEmail'] . "\r\n" . 'Reply-To: ' . $message['senderEmail'] . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($messageDest, $messageSubject, $messageContent, $messageHeaders) !== false) { $this->page()->addVar('messageSent?', true); } else { $this->page()->addVar('error', 'Cannot send message : server error'); } } $this->page()->addVar('title', 'Contact'); }
public function executeDeletePage(\core\HTTPRequest $request) { $this->page()->addVar('title', 'Supprimer un billet'); $this->_addBreadcrumb(); $manager = $this->managers->getManagerOf('gutenberg'); $pageName = $request->getData('pageName'); if ($request->postExists('check')) { if (!$manager->pageExists($pageName)) { $this->page()->addVar('error', 'Cannot find the page named "' . $pageName . '"'); return; } try { $manager->deletePage($pageName); } catch (\Exception $e) { $this->page()->addVar('error', $e->getMessage()); return; } $this->page()->addVar('deleted?', true); } else { $page = $manager->getPage($pageName); $this->page()->addVar('page', $page); } }
public function executeRemoveRepository(\core\HTTPRequest $request) { $this->page()->addVar('title', 'Supprimer un dépôt'); $this->_addBreadcrumb(); $packageManager = $this->managers->getManagerOf('Packagecontrol'); $repoName = $request->getData('name'); $repo = $packageManager->getRemoteRepository($repoName); $this->page()->addVar('repository', $repo); if ($request->postExists('check')) { try { $packageManager->removeRemoteRepository($repoName); } catch (\Exception $e) { $this->page()->addVar('error', $e->getMessage()); return; } $this->page()->addVar('removed?', true); } }