public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('user', array('action' => 'add'));
     }
     try {
         $user = $this->getUserTable()->getUser($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('user', array('action' => 'index'));
     }
     $form = new UserForm();
     $form->bind($user);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($user->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getUserTable()->saveUser($user);
             return $this->redirect()->toRoute('user');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Exemplo n.º 2
0
 public function loginAction()
 {
     $form = new UserForm();
     $form->get('submit')->setValue('Login');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $sm = $this->getServiceLocator();
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $data = $request->getPost();
         $this->userService->login($data, $dbAdapter);
     }
     return array('form' => $form);
 }
Exemplo n.º 3
0
 public function addAction()
 {
     //        $user_session = new \Zend\Session\Container('user');
     //        if ($user_session->email == null) {
     //            return $this->redirect()->toRoute('signin', array(
     //                        'action' => 'signin'
     //            ));
     //        }
     //        if ($user_session->role == 'Operator') {
     //            return array('error' => 'You don\'t have permission to do this action');
     //        }
     $auth = new \Zend\Authentication\AuthenticationService();
     if ($auth->hasIdentity()) {
         $user = $auth->getIdentity();
     } else {
         return $this->redirect()->toRoute('signin', array('action' => 'index'));
     }
     if ($user->role == 'Operator') {
         //$this->flashMessenger()->addMessage('You don\'t have permission to do this action');
         //$this->redirect()->toRoute('add');
         return array('error' => 'You don\'t have permission to do this action');
     }
     $form = new UserForm(null, $user->role);
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $user = new User();
         $form->setInputFilter($user->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $user->exchangeArray($form->getData());
             $this->getUserTable()->saveUser($user);
             return $this->redirect()->toRoute('user');
         } else {
             echo "Fail to add new user";
         }
     }
     return array('form' => $form, 'flashMessages' => $this->flashMessenger()->getMessages());
 }