From 99a14a54e8c2d6fe49f7a973e49a70f3731d7ac1 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Mon, 16 Jan 2006 02:51:02 +0000 Subject: [PATCH] setnew_password_and_mail() gives users a tmp passwords and emails a notice. --- lib/moodlelib.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 527b3d66632..97cc60fcd80 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3821,6 +3821,43 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a } } +/** + * Sets specified user's password and send the new password to the user via email. + * + * @uses $CFG + * @param user $user A {@link $USER} object + * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email + * was blocked by user and "false" if there was another sort of error. + */ +function setnew_password_and_mail($user) { + + global $CFG; + + $site = get_site(); + $from = get_admin(); + + $newpassword = generate_password(); + + if (! set_field('user', 'password', md5($newpassword), 'id', $user->id) ) { + trigger_error('Could not set user password!'); + return false; + } + + $a->firstname = $user->firstname; + $a->sitename = $site->fullname; + $a->username = $user->username; + $a->newpassword = $newpassword; + $a->link = $CFG->wwwroot .'/login/'; + $a->signoff = fullname($from, true).' ('. $from->email .')'; + + $message = get_string('newusernewpasswordtext', '', $a); + + $subject = $site->fullname .': '. get_string('newusernewpasswordsubj'); + + return email_to_user($user, $from, $subject, $message); + +} + /** * Resets specified user's password and send the new password to the user via email. *