示例#1
0
 /** Creation of the login page
  * @access public
  * @return void
  */
 public function indexAction()
 {
     if (null === $this->_auth->getIdentity()) {
         $form = new LoginForm();
         $this->view->form = $form;
         if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
             $authAdapter = $form->username->getValidator('Authorise')->getAuthAdapter();
             $data = $authAdapter->getResultRowObject(NULL, 'password');
             $this->_auth->getStorage()->write($data);
             $this->redirect($this->_helper->loginRedirect());
         } else {
             $this->_auth->clearIdentity();
             //                $this->getFlash()->addMessage('Sorry, there was a
             //                        problem with your submission. Please check and try again');
             $form->populate($this->_request->getPost());
         }
     } else {
         $this->redirect(self::REDIRECT);
     }
 }
示例#2
0
 public function loginAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $this->_redirect('/admin/');
     }
     // the login page
     $loginForm = new LoginForm(array('action' => '/admin/user/login', 'method' => 'post'));
     $request = $this->getRequest();
     //$loginForm->persistData();
     $this->view->form = $loginForm;
     if (!$request->isPost()) {
         return;
     } else {
         //print_r ($request->getParams());
         if (!$this->view->form->isValid($request->getParams())) {
             // do further login validation here.
             $loginForm->populate($request->getParams());
             return;
         }
     }
     $values = $this->view->form->getValues();
     // code will get here if form is valid
     // Let's see if the auth works eh.
     $adapter = new Core_Auth_Adapter($values['login']['email'], $values['login']['password']);
     $adapter->setAction($this);
     $result = $auth->authenticate($adapter);
     if (!$result->isValid()) {
         die('dying from login error, add error messages/flash messages');
         return;
     }
     $url = '/admin';
     if ($request->getParam('redirectTo')) {
         $url = $request->getParam('redirectTo');
     }
     $this->_redirect($url);
 }
 /** On success action
  * @access public
  * @return void
  */
 public function successAction()
 {
     if (null === $this->_auth->getIdentity()) {
         $this->view->headTitle('Login to the system');
         $form = new LoginForm();
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 $authAdapter = $form->username->getValidator('Authorise')->getAuthAdapter();
                 $data = $authAdapter->getResultRowObject(null, 'password');
                 $this->_auth->getStorage()->write($data);
                 $this->redirect($this->_helper->loginRedirect());
             } else {
                 $this->_auth->clearIdentity();
                 $this->getFlash()->addMessage('Sorry, there was a problem with your submission.
             Please check and try again');
                 $form->populate($formData);
             }
         }
     } else {
         $this->redirect('/users/');
     }
 }