Skip to content

Commit

Permalink
MDL-49026 webservice: Remove tokens on password change
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva authored and andrewnicols committed Aug 2, 2016
1 parent 1174a46 commit ce75268
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/moodlelib.php
Expand Up @@ -4450,6 +4450,7 @@ function hash_internal_user_password($password, $fasthash = false) {
*
* Updating the password will modify the $user object and the database
* record to use the current hashing algorithm.
* It will remove Web Services user tokens too.
*
* @param stdClass $user User object (password property may be updated).
* @param string $password Plain text password.
Expand Down Expand Up @@ -4499,6 +4500,10 @@ function update_internal_user_password($user, $password, $fasthash = false) {
// Trigger event.
$user = $DB->get_record('user', array('id' => $user->id));
\core\event\user_password_updated::create_from_user($user)->trigger();

// Remove WS user tokens.
require_once($CFG->dirroot.'/webservice/lib.php');
webservice::delete_user_ws_tokens($user->id);
}

return true;
Expand Down
10 changes: 10 additions & 0 deletions webservice/lib.php
Expand Up @@ -421,6 +421,16 @@ public function delete_user_ws_token($tokenid) {
$DB->delete_records('external_tokens', array('id'=>$tokenid));
}

/**
* Delete all the tokens belonging to a user.
*
* @param int $userid the user id whose tokens must be deleted
*/
public static function delete_user_ws_tokens($userid) {
global $DB;
$DB->delete_records('external_tokens', array('userid' => $userid));
}

/**
* Delete a service
* Also delete function references and authorised user references.
Expand Down

0 comments on commit ce75268

Please sign in to comment.