Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1.     function identify($user=null,$conditions=null){
  2.  
  3.         if (empty($user)) {
  4.             $user = $this->user();
  5.             if (empty($user)) {
  6.                 return null;
  7.             }
  8.         } elseif (is_object($user) && is_a($user, 'Model')) {
  9.             if (!$user->exists()) {
  10.                 return null;
  11.             }
  12.             $user = $user->read();
  13.             $user = $user[$this->userModel];
  14.         } elseif (is_array($user) && isset($user[$this->userModel])) {
  15.             $user = $user[$this->userModel];
  16.         }
  17.  
  18.        
  19.  
  20.         if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']])  && !empty($user[$this->fields['password']])) {
  21.                 if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') {
  22.                     return false;
  23.                 }
  24.                
  25.                     $username = $user[$this->fields['username']];
  26.                     $password = $user[$this->fields['password']];
  27.                
  28.             } elseif (isset($user[$this->userModel . '.' . $this->fields['username']]) && !empty($user[$this->userModel . '.' . $this->fields['username']])) {
  29.                 if (trim($user[$this->userModel . '.' . $this->fields['username']]) == '=' || trim($user[$this->userModel . '.' . $this->fields['password']]) == '=') {
  30.                     return false;
  31.                 }
  32.                
  33.                     $username = $user[$this->userModel . '.' . $this->fields['username']];
  34.                     $password = $user[$this->userModel . '.' . $this->fields['password']];
  35.                
  36.             } else {
  37.                 return false;
  38.             }
  39.  
  40.         $ldap = new Ldapoperator();
  41.  
  42.         $authenticates = $ldap->auth($username, $password);
  43.  
  44.         if($authenticates){
  45.  
  46.                 $userObject=new $this->userModel;
  47.         $user=$userObject->find("first",
  48.                                     array(
  49.                                         'conditions'=> array(
  50.                                             $this->fields['username']=>$username
  51.                                             )
  52.                                         )
  53.                                     );
  54.                 if ($user)
  55.                     return parent::identify($user,$conditions);
  56.         }
  57.  
  58.         return null;
  59.        
  60.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement