From 826725329a51e44be56665cdd7b8ad97c188b380 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 6 Dec 2008 21:20:42 +0000 Subject: [PATCH] MDL-15785 new options for enforcing of enrolment key commplexity and requirements --- course/edit_form.php | 20 +++++++++++++++++++- enrol/manual/config.html | 28 ++++++++++++++++++++++++++++ enrol/manual/enrol.php | 8 ++++++++ group/group_form.php | 10 +++++++++- lang/en_utf8/enrol_manual.php | 2 ++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/course/edit_form.php b/course/edit_form.php index 66cda9f7b2..f79a878795 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -322,6 +322,13 @@ class course_edit_form extends moodleform { $mform->setDefault('enrolpassword', $courseconfig->enrolpassword); $mform->setType('enrolpassword', PARAM_RAW); + if (empty($course) or ($course->password !== '' and $course->id != SITEID)) { + // do not require password in existing courses that do not have password yet - backwards compatibility ;-) + if (!empty($CFG->enrol_manual_requirekey)) { + $mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client'); + } + } + $choices = array(); $choices['0'] = get_string('guestsno'); $choices['1'] = get_string('guestsyes'); @@ -451,7 +458,7 @@ class course_edit_form extends moodleform { /// perform some extra moodle validation function validation($data, $files) { - global $DB; + global $DB, $CFG; $errors = parent::validation($data, $files); if ($foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']))) { @@ -473,6 +480,17 @@ class course_edit_form extends moodleform { } } + if (!empty($CFG->enrol_manual_usepasswordpolicy) and isset($data['enrolpassword']) and $data['enrolpassword'] != '') { + $course = $this->_customdata['course']; + if ($course->password !== $data['enrolpassword']) { + // enforce password policy only if changing password - backwards compatibility + $errmsg = ''; + if (!check_password_policy($data['enrolpassword'], $errmsg)) { + $errors['enrolpassword'] = $errmsg; + } + } + } + return $errors; } } diff --git a/enrol/manual/config.html b/enrol/manual/config.html index 64788b4140..c9b2a1898d 100644 --- a/enrol/manual/config.html +++ b/enrol/manual/config.html @@ -31,5 +31,33 @@ + + enrol_manual_usepasswordpolicy: + +enrol_manual_usepasswordpolicy, ''); +?> + + + + + + + enrol_manual_requirekey: + +enrol_manual_requirekey, ''); +?> + + + + + diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index 33729f4cb1..1e785823b3 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -224,6 +224,14 @@ function config_form($frm) { $frm->enrol_manual_showhint = 1; } + if (!isset($frm->enrol_manual_usepasswordpolicy)) { + $frm->enrol_manual_usepasswordpolicy = 0; + } + + if (!isset($frm->enrol_manual_requirekey)) { + $frm->enrol_manual_requirekey = 0; + } + include ("$CFG->dirroot/enrol/manual/config.html"); } diff --git a/group/group_form.php b/group/group_form.php index 14c568507f..cded5d9f54 100644 --- a/group/group_form.php +++ b/group/group_form.php @@ -42,7 +42,7 @@ class group_form extends moodleform { } function validation($data, $files) { - global $COURSE, $DB; + global $COURSE, $DB, $CFG; $errors = parent::validation($data, $files); @@ -54,6 +54,14 @@ class group_form extends moodleform { } } + if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) { + // enforce password policy only if changing password + $errmsg = ''; + if (!check_password_policy($data['enrolmentkey'], $errmsg)) { + $errors['enrolmentkey'] = $errmsg; + } + } + } else if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', $name); } diff --git a/lang/en_utf8/enrol_manual.php b/lang/en_utf8/enrol_manual.php index d67c1ffb40..ce80a3f411 100644 --- a/lang/en_utf8/enrol_manual.php +++ b/lang/en_utf8/enrol_manual.php @@ -11,6 +11,8 @@ $string['description'] = 'This is the default form of enrolment. There are two m '; $string['enrolmentkeyerror'] = 'That enrolment key was incorrect, please try again.'; $string['enrolname'] = 'Internal Enrolment'; +$string['enrol_manual_requirekey'] = 'Require course enrolment keys in new courses and prevent removing of existing keys.'; $string['enrol_manual_showhint'] = 'Enable this setting to reveal the first character of the enrolment key as a hint if one enters an incorrect key.'; +$string['enrol_manual_usepasswordpolicy'] = 'Use current user password policy for course enrolment keys.'; $string['keyholderrole' ] = 'The role of the user that holds the enrolment key for a course. Displayed to students attempting to enrol on the course.'; ?> -- 2.39.5