Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 24th, 2012  |  syntax: None  |  size: 1.75 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP session is shared with different users
  2. $auth = Zend_Auth::getInstance();
  3.         $authAdapter = new Altergear_Seolista_UserLoginAuthAdapter(
  4.             $loginForm->getLogin(),
  5.             $loginForm->getPassword()
  6.         );
  7.  
  8.         $result = $auth->authenticate($authAdapter);
  9.        
  10. <?php
  11.        
  12. /**
  13.  * The user password
  14.  * @var string $_password
  15.  */
  16. private $_password;
  17.  
  18. /**
  19.  * The Doctrine EntityManager
  20.  * @var EntityManager $_em
  21.  */
  22. private $_em;
  23. public function __construct( $email, $password )
  24. {
  25.     $registry = Zend_Registry::getInstance();
  26.     $this->_em = $registry->entitymanager;
  27.  
  28.     $this->_login = $email;
  29.     $this->_password = $password;
  30. }
  31.  
  32. /**
  33.  * Executes an authentication try
  34.  *
  35.  * @throws Zend_Auth_Adapter_Exception if the authentication failed
  36.  * @return Zend_Auth_Result
  37.  */
  38. public function authenticate()
  39. {
  40.         //check if login is correct
  41.         try{
  42.             $user = $this->_em->getRepository('App_Model_User')
  43.                 ->findOneBy(
  44.                     array(
  45.                         '_email' => $this->_login,
  46.                         '_password' => App_Model_User::encodePassword( $this->_password )
  47.                     )
  48.             );
  49.         }catch( Exception $e ){
  50.             throw new Zend_Auth_Adapter_Exception( 'authentication failed', 0, $e );            
  51.         }
  52.  
  53.         if( $user!==null && $user instanceof App_Model_User && $user->getId() > 0 )
  54.         {
  55.             //login successful
  56.  
  57.             $identity = new stdClass();
  58.             $identity->user = $user;
  59.  
  60.  
  61.             return new Zend_Auth_Result( Zend_Auth_Result::SUCCESS , $identity );
  62.         }else{
  63.             //login failed
  64.             return new Zend_Auth_Result( Zend_Auth_Result::FAILURE, NULL, array('Bitte geben Sie gültige Logindaten an.') );
  65.         }