Advertisement
Guest User

Untitled

a guest
May 28th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2.  
  3.     class ZExt_Auth_Adapter implements Zend_Auth_Adapter_Interface
  4.     {
  5.         const NOT_FOUND_MSG = "Account not found";
  6.         const CREDENTIAL_INVALID_MSG = "Password is invalid";
  7.  
  8.         /**
  9.          *
  10.          * @var Model\User
  11.          */
  12.         protected $user;
  13.    
  14.         /**
  15.          *
  16.          * @var string
  17.          */
  18.         protected $username = "";
  19.        
  20.         /**
  21.          *
  22.          * @var string
  23.          */      
  24.         protected $password = "";      
  25.    
  26.         public function __construct($username, $password)
  27.         {
  28.             $this->username = $username;
  29.             $this->password = $password;
  30.         }
  31.        
  32.         /**
  33.          * Performs an authentication attempt
  34.          *
  35.          * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  36.          * @return Zend_Auth_Result
  37.          */    
  38.         public function authenticate()
  39.         {
  40.             try
  41.             {
  42.                 $this->user = Models\User::authenticate($this->username, $this->password);
  43.                 return $this->createResult(Zend_Auth_Result::SUCCESS);                 
  44.             }
  45.             catch (Exception $e)
  46.             {              
  47.                 if ($e->getMessage() == Models\User::CREDENTIAL_INVALID)
  48.                     return $this->createResult(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(self::CREDENTIAL_INVALID_MSG));
  49.                 elseif ($e->getMessage() == Models\User::NOT_FOUND)
  50.                     return $this->createResult(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, array(self::NOT_FOUND_MSG));
  51.             }          
  52.            
  53.         }
  54.        
  55.         private function createResult($code, $messages = array())
  56.         {
  57.             return new Zend_Auth_Result($code, $this->user, $messages);
  58.         }
  59.        
  60.        
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement