mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 04:58:59 +00:00
Can update user password
This commit is contained in:
parent
8909043413
commit
19292b70b0
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user