Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Added some extra bits to the gitignore to do with composer and fixed …
Browse files Browse the repository at this point in the history
…a problem with the processing of the request data stripping the orginal request varible
  • Loading branch information
Chris-Pratt-Clystnet committed Jun 15, 2018
1 parent b7970b8 commit 9c635e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
.idea
vendor
composer.lock
16 changes: 11 additions & 5 deletions src/Vtiger.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected function login($sessionData)
$tryCounter = 1;
do {
// login using username and accesskey
/** @var ResponseInterface $response */
$response = $this->client->request('POST', $this->url, [
'form_params' => [
'operation' => 'login',
Expand All @@ -138,6 +139,8 @@ protected function login($sessionData)
]
]);

/** @var ResponseInterface $unprocessedResponse */
$unprocessedResponse = $response;
// decode the response
$loginResult = json_decode($response->getBody()->getContents());
$tryCounter++;
Expand All @@ -148,7 +151,7 @@ protected function login($sessionData)
}

// If api login failed
if ($response->getStatusCode() !== 200 || !$loginResult->success) {
if ($unprocessedResponse->getStatusCode() !== 200 || !$loginResult->success) {
if (!$loginResult->success) {
if ($loginResult->error->code == "INVALID_USER_CREDENTIALS" || $loginResult->error->code == "INVALID_SESSIONID") {
if ($this->sessionDriver == 'file') {
Expand All @@ -159,10 +162,10 @@ protected function login($sessionData)
Redis::del('clystnet_vtiger');
}
} else {
$this->_processResult($response);
$this->_processResult($unprocessedResponse);
}
} else {
$this->_checkResponseStatusCode($response);
$this->_checkResponseStatusCode($unprocessedResponse);
}
} else {
// login ok so get sessionid and update our session
Expand Down Expand Up @@ -233,15 +236,18 @@ protected function getToken()
'username' => $this->username
]
]);

$unprocessedResponse = $response;
$processedResponse = json_decode($response->getBody()->getContents());
$tryCounter++;
} while (!isset($processedResponse->success) && $tryCounter <= $this->maxRetries);

if ($tryCounter >= $this->maxRetries) {
throw new VtigerError("Could not complete get token request within ".$this->maxRetries." tries", 6);
}

// decode the response
$challenge = $this->_processResult($response);
$challenge = $this->_processResult($unprocessedResponse);

// Everything ok so create a token from response
$output = array(
Expand Down Expand Up @@ -516,7 +522,7 @@ protected function _checkResponseStatusCode($response)
{

if ($response->getStatusCode() !== 200) {
throw new VtigerError("API request did not complete correctley - Response code: ".$response->getStatusCode(), 1);
throw new VtigerError("API request did not complete correctly - Response code: ".$response->getStatusCode(), 1);
}

}
Expand Down

0 comments on commit 9c635e2

Please sign in to comment.