Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 21b42dd

Browse files
DIOHz0rajsb85
authored andcommittedOct 25, 2017
feat(client): added recovery password end point
1 parent 9380b6c commit 21b42dd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎src/Glpi/Api/Rest/Client.php

+28
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,32 @@ private function addTokens() {
441441

442442
return $headers;
443443
}
444+
445+
/**
446+
* Allows to request password recovery and password reset.
447+
* This endpoint works under the following conditions:
448+
* - GLPI has notifications enabled
449+
* - The email address of the user belongs to a user account.
450+
*
451+
* @param $email
452+
* @param string $recoveryToken
453+
* @param string $newPassword
454+
* @return array
455+
*/
456+
public function lostPassword($email, $recoveryToken = '', $newPassword = '') {
457+
$params['email'] = $email;
458+
if(($recoveryToken && !$newPassword) || (!$recoveryToken && $newPassword)){
459+
throw new InsufficientArgumentsException('The recovery and new password are mandatory');
460+
}
461+
if($recoveryToken && $newPassword){
462+
$params['password_forget_token'] = $recoveryToken;
463+
$params['password'] = $newPassword;
464+
}
465+
$options['body'] = json_encode($params);
466+
$response = $this->request('put', 'lostPassword', $options);
467+
return [
468+
'statusCode' => $response->getStatusCode(),
469+
'body' => $response->getBody()->getContents(),
470+
];
471+
}
444472
}

0 commit comments

Comments
 (0)