3 require_once $CFG->libdir
.'/formslib.php';
5 class login_forgot_password_form
extends moodleform
{
7 function definition() {
8 $mform =& $this->_form
;
9 $renderer =& $mform->defaultRenderer();
11 $mform->addElement('header', '', get_string('passwordforgotten'), '');
13 $mform->addElement('text', 'username', get_string('username'));
14 $mform->setType('username', PARAM_RAW
);
16 $mform->addElement('text', 'email', get_string('email'));
17 $mform->setType('email', PARAM_RAW
);
19 $this->add_action_buttons(true, get_string('ok'));
22 function validation($data) {
27 if ((!empty($data['username']) and !empty($data['email'])) or (empty($data['username']) and empty($data['email']))) {
28 $errors['username'] = get_string('usernameoremail');
29 $errors['email'] = get_string('usernameoremail');
31 } else if (!empty($data['email'])) {
32 if (!validate_email($data['email'])) {
33 $errors['email'] = get_string('invalidemail');
35 } else if (count_records('user', 'email', $data['email']) > 1) {
36 $errors['email'] = get_string('forgottenduplicate');
39 if ($user = get_complete_user_data('email', $data['email'])) {
40 if (empty($user->confirmed
)) {
41 $errors['email'] = get_string('confirmednot');
44 if (!$user and empty($CFG->protectusernames
)) {
45 $errors['email'] = get_string('emailnotfound');
50 if ($user = get_complete_user_data('username', $data['username'])) {
51 if (empty($user->confirmed
)) {
52 $errors['email'] = get_string('confirmednot');
55 if (!$user and empty($CFG->protectusernames
)) {
56 $errors['username'] = get_string('usernamenotfound');
60 if (0 == count($errors)){