Exemplo n.º 1
0
 /**
  * @return boolean
  */
 public function validate()
 {
     $this->actionController->oAcl->getStorage()->clear();
     if (!parent::validate()) {
         return false;
     }
     $sUserLogin = $this->controls['login']->getValue();
     $sUserPassword = $this->controls['password']->getValue();
     $oAuth = Zend_Auth::getInstance();
     $oAuthAdapter = new Zend_Auth_Adapter_DbTable();
     $oAuthAdapter->setTableName('user')->setIdentityColumn('login')->setCredentialColumn('password')->setCredentialTreatment('MD5(?)');
     $oAuthAdapter->setIdentity($sUserLogin)->setCredential($sUserPassword);
     $oSelect = $oAuthAdapter->getDbSelect();
     $oSelect->where('user.deleted = ?', 'no')->joinLeft('client', 'client.id = user.client', array('client_title' => 'client.title'));
     $oResult = $oAuth->authenticate($oAuthAdapter);
     if ($oResult->isValid()) {
         $aResult = (array) $oAuthAdapter->getResultRowObject();
         $aResult['role'] = $aResult['is_admin'] == 0 ? 'user' : 'admin';
         $oAuth->getStorage()->write($aResult);
         return true;
     } else {
         $this->errors[] = 'Invalid login or password';
         return false;
     }
 }