Ejemplo n.º 1
0
 public function loginAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('/');
     }
     $form = new SP_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($_POST)) {
         $username = $request->getParam('name');
         $pwd = $request->getParam('pwd');
         $authAdapter = SP_Application::getAuthAdapter();
         $authAdapter->setIdentity($username)->setCredential($pwd);
         $auth = Zend_Auth::getInstance();
         $result = $auth->authenticate($authAdapter);
         if ($result->isValid()) {
             $storage = $auth->getStorage();
             $storage->write($authAdapter->getResultRowObject(null, 'pwd'));
             $this->_redirect('/');
         } else {
             $this->view->error = "Username" . $username . " or password:"******" is not right.";
         }
     }
     $this->view->form = $form;
     $this->view->title = $this->translator->_('Login');
     $this->getResponse()->insert('content', $this->render('login', null, true));
 }