예제 #1
0
 public function indexAction()
 {
     if ($this->identity()) {
         return $this->redirect()->toRoute('home');
     }
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     try {
         if ($request->isPost()) {
             $this->form->setData($request->getPost()->toArray() ?: []);
             if ($this->form->isValid()) {
                 if ($this->service->login($this->form->getInputFilter())) {
                     $this->flashMessenger()->addSuccessMessage('User login successfully');
                     return $this->redirect()->toRoute('home');
                 } else {
                     $this->form->get('password')->setValue(null);
                     $this->flashMessenger()->addErrorMessage('User name/email or password are incorrect');
                 }
             } else {
                 $this->form->get('password')->setValue(null);
                 $this->flashMessenger()->addErrorMessage('Please fill form correctly');
             }
         }
     } catch (\Exception $e) {
         $this->flashMessenger()->addErrorMessage('An unexpected error has occurred, please contact your system administrator');
     }
     return ['form' => $this->form];
 }
예제 #2
0
 public function testLoginWithInValidFilter()
 {
     $data = ['login' => 'a', 'password' => 'p'];
     $filter = new LoginFormInputFilter();
     $filter->setData($data);
     $this->setExpectedException('LogicException', 'Form is not valid');
     $this->testedObject->login($filter);
 }