### Eclipse Workspace Patch 1.0 #P moodle2cvs Index: login/forgot_password_form.php =================================================================== RCS file: /cvsroot/moodle/moodle/login/forgot_password_form.php,v retrieving revision 1.9 diff -u -r1.9 forgot_password_form.php --- login/forgot_password_form.php 1 Jun 2008 17:53:26 -0000 1.9 +++ login/forgot_password_form.php 12 Aug 2009 10:10:43 -0000 @@ -2,33 +2,73 @@ require_once $CFG->libdir.'/formslib.php'; -class login_forgot_password_form extends moodleform { +class login_forgot_password_form_user extends moodleform { function definition() { $mform =& $this->_form; $renderer =& $mform->defaultRenderer(); - $mform->addElement('header', '', get_string('passwordforgotten'), ''); + $mform->addElement('header', '', get_string('findbyusername'), ''); $mform->addElement('text', 'username', get_string('username')); $mform->setType('username', PARAM_RAW); + // add_action_buttons does not allow the button to be inside the fieldset/header + // so not using that + $submitlabel = get_string('go'); + $mform->addElement('submit', 'submitbutton', $submitlabel); + + } + + function validation($data, $files) { + global $CFG, $DB; + + $errors = parent::validation($data, $files); + if (empty($data['username'])) { + $errors['username'] = get_string('enterusername'); + } + else{ + if ($user = get_complete_user_data('username', $data['username'])) { + if (empty($user->confirmed)) { + // TODO:why is it an e-mail error? sure the email needs to be confirmed but..? + // Should this now be changed? + $errors['email'] = get_string('confirmednot'); + } + } + if (!$user and empty($CFG->protectusernames)) { + $errors['username'] = get_string('usernamenotfound'); + } + } + + return $errors; + } + +} + +class login_forgot_password_form_email extends moodleform { + + function definition() { + $mform =& $this->_form; + $renderer =& $mform->defaultRenderer(); + + $mform->addElement('header', '', get_string('findbyemail'), ''); + $mform->addElement('text', 'email', get_string('email')); $mform->setType('email', PARAM_RAW); - $this->add_action_buttons(true, get_string('ok')); + $submitlabel = get_string('go'); + $mform->addElement('submit', 'submitbutton', $submitlabel); + } - + function validation($data, $files) { global $CFG, $DB; $errors = parent::validation($data, $files); - if ((!empty($data['username']) and !empty($data['email'])) or (empty($data['username']) and empty($data['email']))) { - $errors['username'] = get_string('usernameoremail'); - $errors['email'] = get_string('usernameoremail'); - - } else if (!empty($data['email'])) { + if (empty($data['email'])) { + $errors['email'] = get_string('enteremail'); + } else { if (!validate_email($data['email'])) { $errors['email'] = get_string('invalidemail'); @@ -46,16 +86,7 @@ } } - } else { - if ($user = get_complete_user_data('username', $data['username'])) { - if (empty($user->confirmed)) { - $errors['email'] = get_string('confirmednot'); - } - } - if (!$user and empty($CFG->protectusernames)) { - $errors['username'] = get_string('usernamenotfound'); - } - } + } return $errors; } Index: login/forgot_password.php =================================================================== RCS file: /cvsroot/moodle/moodle/login/forgot_password.php,v retrieving revision 1.57 diff -u -r1.57 forgot_password.php --- login/forgot_password.php 10 Aug 2009 04:58:17 -0000 1.57 +++ login/forgot_password.php 12 Aug 2009 10:10:43 -0000 @@ -86,20 +86,17 @@ die; //never reached } -$mform = new login_forgot_password_form(); +$mform_user = new login_forgot_password_form_user(); +$mform_email = new login_forgot_password_form_email(); -if ($mform->is_cancelled()) { - redirect(get_login_url()); - -} else if ($data = $mform->get_data()) { +if ($userdata = $mform_user->get_data() OR $emaildata = $mform_user->get_data()) { /// find the user in the database and mail info // first try the username - if (!empty($data->username)) { - $user = get_complete_user_data('username', $data->username); + if (!empty($userdata->username)) { + $user = get_complete_user_data('username', $userdata->username); } else { - - $user = get_complete_user_data('email', $data->email); + $user = get_complete_user_data('email', $emaildata->email); } if ($user and !empty($user->confirmed)) { @@ -150,7 +147,8 @@ print_header($strforgotten, $strforgotten, $navigation, 'id_email'); echo $OUTPUT->box(get_string('passwordforgotteninstructions'), 'generalbox boxwidthnormal boxaligncenter'); -$mform->display(); +$mform_user->display(); +$mform_email->display(); echo $OUTPUT->footer(); Index: lang/en_utf8/moodle.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v retrieving revision 1.250 diff -u -r1.250 moodle.php --- lang/en_utf8/moodle.php 3 Aug 2009 07:38:16 -0000 1.250 +++ lang/en_utf8/moodle.php 12 Aug 2009 10:10:43 -0000 @@ -632,6 +632,8 @@ $string['entercourse'] = 'Click to enter this course'; $string['enteremailaddress'] = 'Enter in your email address to reset your password and have the new password sent to you via email.'; +$string['enteremail']='Enter your email address'; +$string['enterusername']='Enter your username'; $string['entries'] = 'Entries'; $string['error'] = 'Error'; $string['errortoomanylogins'] = 'Sorry, you have exceeded the allowed number of login attempts. Restart your browser.'; @@ -682,6 +684,8 @@ $string['filesfolders'] = 'Files/folders'; $string['filloutallfields'] = 'Please fill out all fields in this form'; $string['filter'] = 'Filter'; +$string['findbyusername'] = 'Find by username'; +$string['findbyemail'] = 'Find by email address'; $string['findmorecourses'] = 'Find more courses...'; $string['firstaccess'] = 'First access'; $string['firstdayofweek'] = '0'; @@ -1217,7 +1221,7 @@ $string['passwordconfirmchange'] = 'Confirm password change'; $string['passwordextlink'] = 'The following link has been provided to recover your lost password. This will take you out of Moodle.'; $string['passwordforgotten'] = 'Forgotten password'; -$string['passwordforgotteninstructions'] = 'Your details must first be found in the user database. Please enter either your username or your registered email address in the appropriate box. There is no need to enter both.'; +$string['passwordforgotteninstructions'] = 'To reset your password, submit your username or your email address below. If we can find you in the database, an email will be sent to your email address, with instructions how to get access again.'; $string['passwordnohelp'] = 'No help is available to find your lost password. Please contact your Moodle administrator.'; $string['passwordrecovery'] = 'Yes, help me log in'; $string['passwordsdiffer'] = 'These passwords do not match';