/**
  * Handle login form
  *
  * @return array|\Zend\Http\Response array (form => \Console\Form\Login) or redirect response
  */
 public function loginAction()
 {
     // Don't show the login form if the user is already logged in
     if ($this->_authenticationService->hasIdentity()) {
         return $this->redirectToRoute('client');
     }
     $vars = array('form' => $this->_form);
     if ($this->getRequest()->isPost()) {
         $this->_form->setData($this->params()->fromPost());
         if ($this->_form->isValid()) {
             // Check credentials
             $data = $this->_form->getData();
             if ($this->_authenticationService->login($data['User'], $data['Password'])) {
                 // Authentication successful. Redirect to appropriate page.
                 $session = new \Zend\Session\Container('login');
                 if (isset($session->originalUri)) {
                     // We got redirected here from another page. Redirect to original page.
                     $response = $this->redirect()->toUrl($session->originalUri);
                 } else {
                     // Redirect to default page (client listing)
                     $response = $this->redirectToRoute('client');
                 }
                 $session->getManager()->getStorage()->clear('login');
                 return $response;
             }
         }
         $vars['invalidCredentials'] = true;
     }
     return $vars;
 }
 public function testChangeIdentityValid()
 {
     // Get valid identity first
     $this->_auth->login('user1', 'password1');
     $this->_auth->changeIdentity('test');
     $this->assertEquals('test', $this->_auth->getIdentity());
 }