public function testInitialSetup() { $this->removeAllFromDB(); $serviceManager = $this->controller->getServiceLocator(); $user = $serviceManager->get('user-entity'); $form = new User($user, $serviceManager); $password = $user->hashPassword('Demo123456'); $postParams = ['uname' => 'admin', 'email' => '*****@*****.**', 'password_fields' => ['password' => $password, 'password_repeat' => $password], 'isoCode' => 'en', 'language_name' => 'en', 'user_csrf' => $form->get('user_csrf')->getValue()]; try { $this->mockLogin(); $this->dispatch('/admin/log/initial', Request::METHOD_POST, $postParams); } catch (\Exception $e) { echo "\n" . __FILE__ . ':' . __LINE__ . ' Message: ' . $e->getMessage(); } $this->assertEquals(302, $this->getResponse()->getStatusCode()); }
/** * Cria ou edita um user * @return void */ public function saveAction() { $form = new UserForm(); $request = $this->getRequest(); if ($request->isPost()) { $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); unset($data['submit']); $data['valid'] = 1; $data['password'] = md5($data['password']); if (isset($data['id']) && $data['id'] > 0) { $user = $this->getEntityManager()->find('Admin\\Model\\User', $data['id']); } $user->setData($data); $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); return $this->redirect()->toUrl('/admin/user'); } } $id = (int) $this->params()->fromRoute('id', 0); if ($id > 0) { $user = $this->getEntityManager()->find('Admin\\Model\\User', $id); $form->bind($user); $form->get('submit')->setAttribute('value', 'Edit'); } return new ViewModel(array('form' => $form)); }
/** * @param int $editedUserID The ID of the user being edited * @param UserEntity $currentUser * @param int $newRole The new role of the edited user * @return mixed|null|\Zend\Stdlib\ResponseInterface */ protected function dispatchEdit($editedUserID, $currentUser, $newRole = 1) { if (!is_int($newRole)) { throw new \InvalidArgumentException(); } $this->getRequest()->setMethod(Request::METHOD_PUT); $this->routeMatch->setParam('id', $editedUserID); $form = new User($currentUser, $this->controller->getServiceLocator()->get('entity-manager')); $this->getRequest()->setContent('uname=admin3&email=ventsi2@mail.com&role=' . $newRole . '&user_csrf=' . $form->get('user_csrf')->getValue()); $jsonModel = null; try { $jsonModel = $this->controller->dispatch($this->getRequest()); } catch (\Exception $e) { var_dump($e->getMessage()); } return $jsonModel; }
public function editAction() { $forrest = new Service\BreadcrumbService(); if (!$forrest->exists('user')) { $forrest->set('user', 'admin/user'); } $breadcrumb = $forrest->get('user'); $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('admin/user', array('action' => 'add')); } $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('id' => $id)); $form = new Form\User(); $form->bind($user); $form->get('submit')->setAttribute('value', 'Edit'); $form->get('Country_id')->setValueOptions($this->getCountryOptions()); $request = $this->getRequest(); if ($request->isPost()) { $inputFilter = $this->getServiceLocator()->get('Admin\\InputFilter\\User'); #$form->setInputFilter($inputFilter->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $user = $form->getData(); if ($user->getEmail() == '') { $user->setEmail(NULL); } if ($user->getCountryId() == 0) { $user->setCountry(null); $user->setCountryId(null); } $em->persist($user); $em->flush(); return $this->redirect()->toRoute($breadcrumb->route, $breadcrumb->params, $breadcrumb->options); } else { $logger = $this->getServiceLocator()->get('Logger'); $logger->warn($form->getMessages()); } } return new ViewModel(array('id' => $id, 'form' => $form, 'breadcrumb' => $breadcrumb)); }