Merge branch 'MDL-41170-master' of git://github.com/ankitagarwal/moodle

This commit is contained in:
Damyon Wiese 2013-10-14 14:02:34 +08:00
commit e6338c2c65
3 changed files with 58 additions and 0 deletions

View File

@ -4644,6 +4644,14 @@ function update_internal_user_password($user, $password) {
if ($passwordchanged || $algorithmchanged) {
$DB->set_field('user', 'password', $hashedpassword, array('id' => $user->id));
$user->password = $hashedpassword;
// Trigger event.
$event = \core\event\user_updated::create(array(
'objectid' => $user->id,
'context' => context_user::instance($user->id)
));
$event->add_record_snapshot('user', $user);
$event->trigger();
}
return true;
@ -5861,6 +5869,15 @@ function setnew_password_and_mail($user, $fasthash = false) {
$hashedpassword = hash_internal_user_password($newpassword, $fasthash);
$DB->set_field('user', 'password', $hashedpassword, array('id' => $user->id));
$user->password = $hashedpassword;
// Trigger event.
$event = \core\event\user_updated::create(array(
'objectid' => $user->id,
'context' => context_user::instance($user->id)
));
$event->add_record_snapshot('user', $user);
$event->trigger();
$a = new stdClass();
$a->firstname = fullname($user, true);

View File

@ -2523,4 +2523,44 @@ class core_moodlelib_testcase extends advanced_testcase {
$this->assertSame($user2->email, $result[1]->to);
$this->assertSame($user1->email, $result[1]->from);
}
/**
* Test user_updated event trigger by various apis.
*/
public function test_user_updated_event() {
global $DB, $CFG;
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
// Set config to allow email_to_user() to be called.
$CFG->noemailever = false;
// Update user password.
$sink = $this->redirectEvents();
$sink2 = $this->redirectEmails(); // Make sure we are redirecting emails.
setnew_password_and_mail($user);
update_internal_user_password($user, 'randompass');
$events = $sink->get_events();
$sink->close();
$sink2->close();
// Test updated value.
$dbuser = $DB->get_record('user', array('id' => $user->id));
$this->assertSame($user->firstname, $dbuser->firstname);
$this->assertNotSame('M00dLe@T', $dbuser->password);
// Test event.
foreach ($events as $event) {
$this->assertInstanceOf('\core\event\user_updated', $event);
$this->assertSame($user->id, $event->objectid);
$this->assertSame('user_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($user, $event);
$this->assertEquals(context_user::instance($user->id), $event->get_context());
$expectedlogdata = array(SITEID, 'user', 'update', 'view.php?id='.$user->id, '');
$this->assertEventLegacyLogData($expectedlogdata, $event);
}
}
}

View File

@ -47,6 +47,7 @@ information provided here is intended especially for developers.
backups which supports both compression formats; get_file_packer('application/vnd.moodle.backup').
* New optional parameter to stored_file::get_content_file_handle to open file handle with 'gzopen' instead
of 'fopen' to read gzip-compressed files if required.
* update_internal_user_password() and setnew_password_and_mail() now trigger user_updated event.
DEPRECATIONS:
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices