Can update user password

This commit is contained in:
Pierre 2018-04-20 10:17:52 +02:00
parent 8909043413
commit 19292b70b0
2 changed files with 43 additions and 0 deletions

View File

@ -157,6 +157,30 @@ class SettingsController {
return array("success" => "The security settings of the user have been successfully saved !");
}
/**
* Update user password
*
* @url POST /settings/update_password
*/
public function updatePassword(){
//User login required
user_login_required();
//Check the old password
check_post_password(userID, "oldPassword");
//Get and save the new password
$newPassword = postString("newPassword");
//Try to save password
if(!components()->account->set_new_user_password(userID, $newPassword))
Rest_fatal_error(500, "Could not update user password!");
//Success
return array("success" => "The password has been updated !");
}
/**
* Turn a GeneralSettings object into a valid API object
*

View File

@ -224,6 +224,25 @@ class AccountComponent {
return CS::get()->db->count(self::USER_TABLE, $sql_conds, $values) > 0;
}
/**
* Update user password
*
* @param int $userID Target user ID
* @param string $password The new password to set to the user
* @return bool TRUE in case of success / FALSE else
*/
public function set_new_user_password(int $userID, string $password) : bool {
//Crypt the password
$password = $this->cryptPassword($password);
//Prepare database update
$modif = array("password" => $password);
//Perform the request
return CS::get()->db->updateDB(self::USER_TABLE, "ID = ?", $modif, array($userID));
}
/**
* Crypt user password
*