Пример #1
0
 /**
  * Checks the given credentials against keeo. Returns true if the credentials are correct.
  * Throws an exception when the login failed.
  *
  * @param $stemnumber
  * @param $password
  * @return bool
  * @throws InvalidResponseException
  * @throws CredentialsDoNotMatchException
  */
 public function userLogin($stemnumber, $password)
 {
     $credentialsCorrect = false;
     $response = $this->keeoConnector->post('/person/login.json', array('login' => $stemnumber, 'password' => $password));
     // validate response
     if (!empty($response->headers['X-Json'])) {
         // remove the ( and ) at the beginning en ending of this string
         $json = substr($response->headers['X-Json'], 1, -1);
         $receivedData = json_decode($json, true);
         if (isset($receivedData['result']) && ($receivedData['result'] = 'ok' && isset($receivedData['authenticated']))) {
             if ($receivedData['authenticated']) {
                 if (!isset($receivedData['hash'])) {
                     throw new InvalidResponseException();
                 }
                 // check the hash
                 $receivedHash = $receivedData['hash'];
                 $calculatedHash = md5($stemnumber . $this->config->getUserLoginSalt() . $password . date('YmdH'));
                 if ($receivedHash == $calculatedHash) {
                     $credentialsCorrect = true;
                 }
             } else {
                 $message = '';
                 if (isset($receivedData['message'])) {
                     $message = $receivedData['message'];
                 }
                 throw new CredentialsDoNotMatchException($message);
             }
         } else {
             throw new InvalidResponseException();
         }
     }
     return $credentialsCorrect;
 }