Esempio n. 1
0
 /**
  * (non-PHPdoc)
  *
  * @see \PhalconRest\Authentication\UserProfile::loadProfileByToken()
  */
 public function loadProfile($search)
 {
     if ($search == "token = 'HACKYHACKERSON'") {
         // load config defined user id
         $search = 'user_id = 103';
     } else {
         $search .= " and active = 1";
     }
     $users = \PhalconRest\Models\Users::find($search);
     switch (count($users)) {
         case 0:
             throw new HTTPException("No user found", 401, array('dev' => "No valid user was found", 'code' => '347589347598'));
             break;
         case 1:
             foreach ($users as $user) {
                 $this->id = $user->id;
                 $this->firstName = $user->first_name;
                 $this->lastName = $user->last_name;
                 $this->email = $user->email;
                 if ($user->user_type == 'Owner') {
                     $this->accountId = $user->owners->account_id;
                 }
                 $this->gender = $user->gender;
                 $this->expiresOn = 'NOT IMPLEMENTED YET';
                 $this->token = 'NOT IMPLEMENTED YET';
             }
             break;
         default:
             throw new HTTPException("Multiple users found!", 401, array('dev' => "More than one user was found, when only one was expected.", 'code' => '347589347598'));
             break;
     }
     return true;
 }
Esempio n. 2
0
 public function search()
 {
     $records = Users::find();
     $records = $records->toArray();
     $results = array();
     foreach ($records as $record) {
         $match = true;
         foreach ($this->searchFields as $field => $value) {
             if (!(strpos(strtolower($record[$field]), strtolower($value)) !== FALSE)) {
                 $match = false;
             }
         }
         if ($match) {
             $results[] = $record;
         }
     }
     return $results;
 }
Esempio n. 3
0
 /**
  * check the username & password against the local user table source
  *
  * @param string $email            
  * @param false $password            
  * @return boolean
  */
 function authenticate($email, $password)
 {
     $users = \PhalconRest\Models\Users::find(array("email = '{$email}'", "active" => 1));
     switch ($users->count()) {
         case 1:
             $user = $users->getFirst();
             // compare password
             $security = $this->di->get('security');
             if ($security->checkHash($password, $user->password)) {
                 // The password is valid
                 return true;
             } else {
                 return false;
             }
             break;
         default:
             // to many user accounts found
             return false;
             break;
     }
 }