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; }
/** * @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)); }
/** * @return array|\Zend\Http\Response */ public function loginUserAction() { $req = $this->getRequest(); if ($req->isPost()) { $data = $req->getPost(); $storage = new UserStorage($this->serviceLocator->get('ADB')); $res = $storage->loginUser($data['username'], $data['password'], true); if ($res['result']) { if (!empty(SessionStorage::getNextRoute())) { return $this->redirect()->toUrl(SessionStorage::getNextRoute()); } return $this->redirect()->toRoute('display-index'); } return ['outcome' => $res, 'username' => $data['username']]; } return []; }
public function editStampTypeAction() { $request = $this->getRequest(); $result = []; $id = $request->getQuery('id'); $storage = new StampStorage($this->serviceLocator->get('adb')); if ($request->isPost()) { $postData = (array) $request->getPost(); $postData['id'] = $id; if (!isset($postData['active'])) { $postData['active'] = 0; } $postData['user_modified'] = SessionStorage::getUserId(); $storage->updateStampType($postData); $result['updated'] = true; } $stamp = $storage->fetchStamp($id); $result['stamp'] = $stamp; $result['error'] = false; if (empty($stamp)) { $result['error'] = true; } return $result; }