Пример #1
1
 public function updateAction()
 {
     $request = $this->getRequest();
     $recipe = $this->readService->findById($this->params('id'));
     if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('recipe/update');
     $viewModel->setVariables(['form' => $this->form]);
     $this->form->bind($recipe);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $this->writeService->save($this->form->getData());
                 $this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert');
                 $this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]);
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         }
     }
     $this->layout('layout/backend');
     return $viewModel;
 }
Пример #2
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $logContent = '';
     // initialize when no submit anymore
     $data = [];
     $data['logmessage'] = $this->form->get('logmessage')->getValue();
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             $data = $this->form->getData();
             $this->loggerPriority = $data['logpriority'];
             if ($data['logformat'] !== 'simple') {
                 $this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat'];
                 unset($this->loggerConfig['writers'][0]['options']['formatter']['options']);
             }
         }
     }
     $logger = new Logger($this->loggerConfig);
     // save log data to buffer and make it variable
     ob_start();
     $logger->log((int) $this->loggerPriority, $data['logmessage']);
     $logContent = ob_get_clean();
     return new ViewModel(['form' => $this->form, 'logContent' => $logContent]);
 }
Пример #3
0
 public function manageAction()
 {
     if (false === $this->authorizationService->isGranted('user.admin')) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $userId = $this->params('id', null);
     if (null === $userId) {
         return $this->listUsers();
     }
     $userObject = $this->userService->findById($userId);
     if (false === $userObject instanceof UserEntity) {
         return $this->listUsers();
     }
     $request = $this->getRequest();
     $viewModel = new ViewModel();
     $viewModel->setTemplate('user/update');
     $viewModel->setVariables(['form' => $this->form]);
     $this->form->bind($userObject);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $this->userService->save($this->form->getData());
                 $this->flashMessenger()->addSuccessMessage('User successfully updated');
                 return $this->redirect()->toRoute('zfcuser/manage');
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         } else {
             var_dump($this->form->getMessages());
         }
     }
     return $viewModel;
 }
Пример #4
0
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->dashboardForm->setData($this->getRequest()->getPost());
         if ($this->dashboardForm->isValid()) {
             $data = $this->dashboardForm->getData();
             $this->dashboardTaskService->persistFromArray($data);
             return $this->redirect()->toRoute('dashboard/manage');
         }
     }
     return new ViewModel(['dashboardForm' => $this->dashboardForm]);
 }
Пример #5
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $formMessages = [];
     $isPost = false;
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         $this->form->isValid();
         $formMessages = $this->form->getMessages();
         $isPost = true;
     }
     return new ViewModel(['form' => $this->form, 'formMessages' => $formMessages, 'isPost' => $isPost]);
 }
Пример #6
0
 /**
  * 
  * @return ViewModel|Response
  */
 public function indexAction()
 {
     if (!is_null($this->identity())) {
         return $this->redirect()->toRoute($this->loginRedirectRoute);
     }
     if ($this->getRequest()->isPost()) {
         $this->loginForm->setData($this->getRequest()->getPost());
         if ($this->loginForm->isValid()) {
             return $this->redirect()->toRoute($this->loginRedirectRoute);
         }
     }
     return new ViewModel(array('loginForm' => $this->loginForm));
 }
Пример #7
0
 public function indexAction()
 {
     $this->settingsForm->setData($this->settingsManager->getAll());
     if ($this->getRequest()->isPost()) {
         $this->settingsForm->setData($this->getRequest()->getPost());
         if ($this->settingsForm->isValid()) {
             $data = $this->settingsForm->getData();
             $this->settingsManager->set('application_title', $data['application_title']);
             $this->settingsManager->flush();
             $this->flashMessenger()->addSuccessMessage('The settings have been saved.');
             return $this->redirect()->toRoute('admin/system/settings');
         }
     }
     return new ViewModel(['settingsForm' => $this->settingsForm]);
 }
Пример #8
0
 public function updateAction()
 {
     $person = $this->contactService->findPerson($this->params('id'));
     if (!$person) {
         return $this->notFoundAction();
     }
     $this->contactForm->bind($person);
     if ($this->getRequest()->isPost()) {
         $this->contactForm->setData($this->getRequest()->getPost());
         if ($this->contactForm->isValid()) {
             $person = $this->contactService->persistContact($this->contactForm->getData());
             return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_PERSON, 'id' => $person->getId()->toString()]);
         }
     }
     return new ViewModel(['person' => $person, 'contactForm' => $this->contactForm]);
 }
Пример #9
0
 public function updateAction()
 {
     $company = $this->contactService->findCompany($this->params('id'));
     if (!$company) {
         return $this->notFoundAction();
     }
     $this->contactForm->bind($company);
     if ($this->getRequest()->isPost()) {
         $this->contactForm->setData($this->getRequest()->getPost());
         if ($this->contactForm->isValid()) {
             $company = $this->contactService->persistContact($this->contactForm->getData());
             return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_COMPANY, 'id' => $company->getId()->toString()]);
         }
     }
     return new ViewModel(['company' => $company, 'contactForm' => $this->contactForm]);
 }
Пример #10
0
 public function resetPasswordAction()
 {
     $code = $this->params('code');
     if ($code) {
         $this->resetPasswordForm->get('code')->setValue($code);
     }
     if ($this->getRequest()->isPost()) {
         $this->resetPasswordForm->setData($this->getRequest()->getPost());
         if ($this->resetPasswordForm->isValid()) {
             $data = $this->resetPasswordForm->getData();
             $this->passwordChanger->resetAccountPassword($data['code'], $data['credential']);
             return $this->redirect()->toRoute('login');
         }
     }
     return new ViewModel(['resetPasswordForm' => $this->resetPasswordForm, 'code' => $code]);
 }
Пример #11
0
 /**
  * Use the form to get barcode image from selected barcode object.
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     //default value without post parameter
     $barcodeOptions = ['text' => '123456789'];
     $barcode = Barcode::factory('codabar', 'image', $barcodeOptions);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             $barcodeOptions = ['text' => $this->form->getData()['barcode-object-text']];
             $barcode = Barcode::factory($this->form->getData()['barcode-object-select'], 'image', $barcodeOptions);
         }
     }
     imagegif($barcode->draw(), './data/barcode.gif');
     return new ViewModel(['form' => $this->form]);
 }
Пример #12
0
 public function changesAction()
 {
     $siteId = $this->services->getUtilityService()->getSiteId();
     $site = $this->services->getSiteService()->find($siteId);
     $fromControl = $this->dateIntervalForm->get(DateIntervalForm::FROM_DATE_NAME);
     $toControl = $this->dateIntervalForm->get(DateIntervalForm::TO_DATE_NAME);
     $lastDate = $site->getLastUpdate();
     $lastDate->setTime(23, 59, 59);
     $fromControl->setAttribute('max', $lastDate->format('Y-m-d'));
     $toControl->setAttribute('max', $lastDate->format('Y-m-d'));
     $from = clone $lastDate;
     $from->sub(new \DateInterval('P1M'));
     $to = $lastDate;
     $fromControl->setValue($from->format('Y-m-d'));
     $toControl->setValue($to->format('Y-m-d'));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $this->dateIntervalForm->setData($request->getPost());
         if ($this->dateIntervalForm->isValid()) {
             $from = \DateTime::createFromFormat('Y-m-d', $fromControl->getValue());
             $to = \DateTime::createFromFormat('Y-m-d', $toControl->getValue());
         }
     }
     $from->setTime(0, 0, 0);
     $to->setTime(23, 59, 59);
     $result = array('intervalForm' => $this->dateIntervalForm, 'site' => $site, 'members' => $this->getMembersData($siteId, $from, $to), 'pages' => $this->getPagesData($siteId, $from, $to), 'revisions' => $this->getRevisionsData($siteId, $from, $to), 'votes' => $this->getVotesData($siteId, $from, $to));
     return new ViewModel($result);
 }
Пример #13
0
 public function indexAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->installForm->setData(array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()));
         if ($this->installForm->isValid()) {
             $data = $this->installForm->getData();
             if ($data['plugin']['error'] === 0) {
                 $this->pluginManager->installFile($data['plugin']['tmp_name']);
             } else {
                 $this->pluginManager->installExternal($data['location']);
             }
             $this->flashMessenger()->addSuccessMessage('The plugin has been installed.');
             return $this->redirect()->toRoute('admin/system/plugins');
         }
     }
     return new ViewModel(['plugins' => $this->pluginManager->getPlugins(), 'installForm' => $this->installForm]);
 }
Пример #14
0
 public function editAction()
 {
     $client = $this->clientRepository->find($this->params('clientId'));
     if ($client === null) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $this->clientForm->bind($client);
     if ($this->getRequest()->isPost()) {
         $this->clientForm->setData($this->getRequest()->getPost());
         if ($this->clientForm->isValid()) {
             $this->clientService->persist($this->clientForm->getData());
             $this->redirect()->toRoute('clients/show', ['clientId' => $client->getId()]);
         }
     }
     return new ViewModel(['form' => $this->clientForm]);
 }
Пример #15
0
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $post = $this->postService->findPost($this->params('id'));
     $this->postForm->bind($post);
     if ($request->isPost()) {
         $this->postForm->setData($request->getPost());
         if ($this->postForm->isValid()) {
             try {
                 $this->postService->savePost($this->postForm->getData());
                 return $this->redirect()->toRoute('blog');
             } catch (\Exception $e) {
             }
         }
     }
     return new ViewModel(array('form' => $this->postForm));
 }
Пример #16
0
 public function updateAction()
 {
     $cronjob = $this->cronManager->find($this->params('id'));
     if (!$cronjob) {
         return $this->notFoundAction();
     }
     $this->cronjobForm->bind($cronjob);
     if ($this->getRequest()->isPost()) {
         $this->cronjobForm->setData($this->getRequest()->getPost());
         if ($this->cronjobForm->isValid()) {
             $data = $this->cronjobForm->getData();
             $this->cronManager->persist($data);
             return $this->redirect()->toRoute('admin/system/cron');
         }
     }
     return new ViewModel(['cronjob' => $cronjob, 'cronjobForm' => $this->cronjobForm]);
 }
Пример #17
0
 public function updateAction()
 {
     $group = $this->groupTaskService->find($this->params('id'));
     if (!$group) {
         return $this->notFoundAction();
     }
     $this->groupForm->bind($group);
     if ($this->getRequest()->isPost()) {
         $this->groupForm->setData($this->getRequest()->getPost());
         if ($this->groupForm->isValid()) {
             $group = $this->groupForm->getData();
             $this->groupTaskService->persist($group);
             $this->flashMessenger()->addSuccessMessage('The group has been updated.');
             return $this->redirect()->toRoute('admin/usermanagement/groups');
         }
     }
     return new ViewModel(['group' => $group, 'groupForm' => $this->groupForm]);
 }
Пример #18
0
 public function validate(FormInterface $form, array $data)
 {
     $argv = compact('form', 'data');
     $this->getEventManager()->trigger(__METHOD__ . '.pre', $this, $argv);
     $form->setData($data);
     $isValid = $form->isValid();
     $this->getEventManager()->trigger(__METHOD__ . '.post', $this, $argv + array('success' => $isValid));
     return $isValid;
 }
Пример #19
0
 public function editAction()
 {
     $project = $this->projectRepository->find($this->params('projectId'));
     if ($project === null) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $this->projectForm->get('client')->setValue($project->getClient()->getName());
     $this->projectForm->bind($project);
     if ($this->getRequest()->isPost()) {
         $this->projectForm->setData($this->getRequest()->getPost());
         if ($this->projectForm->isValid()) {
             $this->projectService->persist($this->projectForm->getData());
             $this->redirect()->toRoute('clients/show', ['clientId' => $project->getClient()->getId()], ['fragment' => 'project-table']);
         }
     }
     return new ViewModel(['form' => $this->projectForm]);
 }
Пример #20
0
 public function loginTfaAction()
 {
     if (!$this->authSession->identity) {
         return $this->redirect()->toRoute('login');
     }
     if ($this->getRequest()->isPost()) {
         $this->verifyCodeForm->setData($this->getRequest()->getPost());
         /** @var AccountInterface $account */
         $account = $this->zourceIdentity($this->authSession->identity)->getAccount();
         /** @var \ZourceUser\InputFilter\VerifyCode $inputFilter */
         $inputFilter = $this->verifyCodeForm->getInputFilter();
         $inputFilter->setOneTimePasswordType($account->getTwoFactorAuthenticationType());
         $inputFilter->setOneTimePasswordCode($account->getTwoFactorAuthenticationCode());
         if ($this->verifyCodeForm->isValid()) {
             $this->authSession->verified = true;
             return $this->redirectAfterLogin($account);
         }
     }
     return new ViewModel(['verifyCodeForm' => $this->verifyCodeForm]);
 }
Пример #21
0
 public function updateAction()
 {
     $application = $this->applicationService->getApplication($this->params('id'));
     if (!$application) {
         return $this->notFoundAction();
     }
     if ($application->getAccount() !== $this->zourceAccount()) {
         return $this->notFoundAction();
     }
     $this->applicationForm->bind($application);
     if ($this->getRequest()->isPost()) {
         $this->applicationForm->setData($this->getRequest()->getPost());
         if ($this->applicationForm->isValid()) {
             $updatedApplication = $this->applicationForm->getData();
             $this->applicationService->persistApplication($updatedApplication);
             return $this->redirect()->toRoute('settings/applications');
         }
     }
     return new ViewModel(['application' => $application, 'applicationForm' => $this->applicationForm]);
 }
Пример #22
0
 public function editAction()
 {
     $request = $this->getRequest();
     $page = $this->pageService->findPage($this->params('id'));
     $this->pageForm->bind($page);
     if ($request->isPost()) {
         $this->pageForm->setData($request->getPost());
         if ($this->pageForm->isValid()) {
             try {
                 $this->pageService->savePage($page);
                 return $this->redirect()->toRoute('admin');
             } catch (\Exception $e) {
                 // Some DB Error happened
                 $view = new ViewModel(array('message' => $e->getMessage()));
                 $view->setTemplate('error/error');
                 return $view;
             }
         }
     }
     return new ViewModel(array('form' => $this->pageForm));
 }
Пример #23
0
 public function indexAction()
 {
     $result = ['result' => false, 'message' => ''];
     $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $login = new LoginInputFilter();
         $this->loginForm->setInputFilter($login->getInputFilter());
         $this->loginForm->setData($request->getPost());
         if ($this->loginForm->isValid()) {
             $result = ['result' => true, 'message' => 'Ajax request success'];
         } else {
             $result = ['result' => false, 'message' => $this->loginForm->getMessages()];
         }
     }
     if (!$viewModel instanceof JsonModel && $request->isXmlHttpRequest()) {
         $viewModel = new JsonModel();
     }
     $viewModel->setVariables(['form' => $this->loginForm, 'data' => $result]);
     return $viewModel;
 }
 /**
  * Invoke as function
  * @param \Zend\Form\FormInterface $oForm
  * @param string $sMessage
  * @param string $bDismissable
  * @return string|null
  */
 public function __invoke(\Zend\Form\FormInterface $oForm = null, $sMessage = null, $bDismissable = false)
 {
     if (!$oForm) {
         return $this;
     }
     if (!$sMessage) {
         $sMessage = $this->defaultErrorText;
     }
     if ($oForm->hasValidated() && !$oForm->isValid()) {
         return $this->render($oForm, $sMessage, $bDismissable);
     }
     return null;
 }
Пример #25
0
 public function deleteAction()
 {
     $request = $this->getRequest();
     $recipe = $this->readService->findById($this->params('id'));
     if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('recipe/delete');
     $viewModel->setVariables(['recipe' => $recipe, 'form' => $this->form]);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $this->writeService->delete($recipe);
                 $this->flashMessenger()->addSuccessMessage('Rezept wurde erfolgreich gelöscht!');
                 return $this->redirect()->toRoute('recipe');
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         }
     }
     return $viewModel;
 }
Пример #26
0
 public function createAction()
 {
     if (false === $this->authorizationService->isGranted('recipe.add')) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('recipe/add');
     $viewModel->setVariables(['form' => $this->form]);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $recipe = $this->form->getData();
                 $this->writeService->save($recipe);
                 return $this->redirect()->toRoute('recipe/read', ['id' => $recipe->getId()]);
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         }
     }
     $this->layout('layout/backend');
     return $viewModel;
 }
Пример #27
0
 public function editPageRepository(FormInterface $form)
 {
     $page = $form->getObject();
     if (!$form->isValid()) {
         throw new RuntimeException(print_r($form->getMessages(), true));
     }
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $formClone = clone $form;
     $formClone->bind($page);
     $formClone->setData($data);
     $formClone->isValid();
     $this->assertGranted('page.update', $page);
     $this->getObjectManager()->persist($page);
     return $page;
 }
Пример #28
0
 public function createRole(FormInterface $form)
 {
     $this->assertGranted('authorization.role.create');
     if (!$form->isValid()) {
         throw new RuntimeException(print_r($form->getMessages(), true));
     }
     $processingForm = clone $form;
     $data = $processingForm->getData(FormInterface::VALUES_AS_ARRAY);
     $processingForm->bind(new Role());
     $processingForm->setData($data);
     if (!$processingForm->isValid()) {
         throw new RuntimeException(print_r($processingForm->getMessages(), true));
     }
     $this->objectManager->persist($processingForm->getObject());
     return $processingForm->getObject();
 }
Пример #29
0
 public function updateAction()
 {
     /** @var \ZourceUser\Entity\Account $account */
     $account = $this->accountTaskService->find($this->params('id'));
     if (!$account) {
         return $this->notFoundAction();
     }
     $this->accountForm->bind($account);
     if ($this->getRequest()->isPost()) {
         $this->accountForm->setData($this->getRequest()->getPost());
         if ($this->accountForm->isValid()) {
             $account = $this->accountForm->getData();
             $this->accountTaskService->persist($account);
             return $this->redirect()->toRoute('admin/usermanagement/accounts');
         }
     }
     return new ViewModel(['account' => $account, 'accountForm' => $this->accountForm]);
 }
Пример #30
0
 /**
  * @param  FormInterface $form
  * @return bool|array
  */
 protected function handleGetRequest(FormInterface $form)
 {
     $container = $this->getSessionContainer();
     if (null === $container->post) {
         // No previous post, bail early
         unset($container->files);
         return false;
     }
     // Collect data from session
     $post = $container->post;
     $errors = $container->errors;
     $isValid = $container->isValid;
     unset($container->post);
     unset($container->errors);
     unset($container->isValid);
     // Fill form with the data first, collections may alter the form/filter structure
     $form->setData($post);
     // Remove File Input validators and filters on previously uploaded files
     // in case $form->isValid() or $form->bindValues() is run
     $inputFilter = $form->getInputFilter();
     $this->traverseInputs($inputFilter, $post, function ($input, $value) {
         if ($input instanceof FileInput) {
             $input->setAutoPrependUploadValidator(false)->setValidatorChain(new ValidatorChain())->setFilterChain(new FilterChain());
         }
         return $value;
     });
     // set previous state
     $form->isValid();
     // re-validate to bind values
     if (null !== $errors) {
         $form->setMessages($errors);
         // overwrite messages
     }
     $this->setProtectedFormProperty($form, 'isValid', $isValid);
     // force previous state
     // Clear previous files from session data if form was valid
     if ($isValid) {
         unset($container->files);
     }
     return $post;
 }