/** * @param MvcEvent $e * @return void */ public function onDispatch(MvcEvent $e) { parent::onDispatch($e); $userStorage = new UserStorage($this->serviceLocator->get('ADB')); $userStorage->userLoggedIn(); $loggedIn = SessionStorage::getValue('user-logged-in'); $this->layout()->setVariable('loggedIn', $loggedIn); if ($loggedIn) { $this->layout()->setVariable('userData', $userStorage->fetchCurrentUser()); } else { $this->layout()->setVariable('userData', ['username' => 'not logged in']); } $configStorage = new ConfigStorage($this->serviceLocator->get('ADB')); $this->layout()->setVariable('configuration', $configStorage->getConfiguration(1)); }
public function setConfigValueAction() { $vm = new ViewModel(); $vm->setTerminal(true); $sessionStorage = new SessionStorage(); $configStorage = new ConfigStorage($this->serviceLocator->get('adb')); $request = $this->getRequest(); if (!$request->isPost()) { $id = $this->params()->fromQuery('id'); if ($id === null) { // no config value id given $vm->setVariable('error', true); return $vm; } $currentValue = $configStorage->getRecord($id); $token = Common::generateToken(); $vm->setVariables(['token' => $token, 'id' => $id, 'c_name' => $currentValue['c_name'], 'c_value' => $currentValue['c_value'], 'e_value' => $currentValue['e_value']]); $sessionStorage->setValue('set-config-value-token', $token); return $vm; } $vm->setTemplate('admin/config/empty.phtml'); $post = $request->getPost(); $token = $post['token']; $storedToken = $sessionStorage->getValue('set-config-value-token'); $sessionStorage->setValue('set-config-value-token', null); if ($token != $storedToken) { echo XmlResponder::generalResponse('300', 'Invalid token provided'); return $vm; } $id = isset($post['id']) ? $post['id'] : null; $c_name = $post['c_name']; $c_value = $post['c_value']; $e_value = $post['e_value']; $newId = $configStorage->setValue($c_name, $c_value); if (!empty($e_value)) { $configStorage->setExtendedValue($newId, $e_value); } else { // remove extension if exists $rec = $configStorage->getRecord($newId); if ($rec['extended'] > 0) { $configStorage->removeExtension($rec['extended']); } } echo XmlResponder::generalResponse('200', 'OK'); return $vm; }