Skip to content

Commit

Permalink
Update code for adding delete user code
Browse files Browse the repository at this point in the history
  • Loading branch information
techseriadevs committed Dec 18, 2017
1 parent db73c19 commit 161c433
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.9-dev"
"dev-master": "1.0.11-dev"
}
},
"config": {
Expand Down
24 changes: 24 additions & 0 deletions src/GluuClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ public function updateUser($id,\Mrpvision\Gluu\Models\User $user) {
throw new Models\Exception\UserException("Getting code {$ex->getCode()} from SSO server in updating user.");
}
}
public function DeleteUser($id) {
$accessToken = $this->requestTokens();
$endpoint = $this->getProviderConfigValue("user_endpoint").'/' . $id;
$options = [
"headers" => [
"Authorization" => sprintf('Bearer %s', $accessToken->getToken()),
]
];

try {
$this->getOptions($options);
$response = $this->httpClient->delete(
$endpoint, $options
);
if ($response->getStatusCode() == 204) {
return true;
}
throw new Exception\SSOException("Getting code {$response->getStatusCode()} from SSO server while creating an user's information.");
} catch (\Exception $ex) {
throw new Models\Exception\UserException("Getting code {$ex->getCode()} from SSO server in deleting user.");
} catch (\GuzzleHttp\Exception\ClientException $ex) {
throw new Models\Exception\UserException("Getting code {$ex->getCode()} from SSO server in deleting user.");
}
}

public function CreateUser(\Mrpvision\Gluu\Models\User $user) {
$accessToken = $this->requestTokens();
Expand Down
11 changes: 11 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public function put($requestUri, array $options = [])
{
return $res = $this->client->request('PUT', $requestUri,$options);
}
/**
* @param string $requestUri
* @param array $postData
* @param array $requestHeaders
*
* @return Request
*/
public function delete($requestUri, array $options = [])
{
return $res = $this->client->request('DELETE', $requestUri,$options);
}

/**
* @param string $key
Expand Down
3 changes: 3 additions & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public function update(\Mrpvision\Gluu\GluuClient $gluu){
public function save(\Mrpvision\Gluu\GluuClient $gluu){
return $gluu->CreateUser($this);
}
public function delete(\Mrpvision\Gluu\GluuClient $gluu){
return $gluu->DeleteUser($this->id);
}

}

Expand Down

0 comments on commit 161c433

Please sign in to comment.