Skip to content
Browse files

MDL-15785 new options for enforcing of enrolment key commplexity and …

…requirements; backported from HEAD
  • Loading branch information...
1 parent 540875d commit 1d7651e19fa6ecefe723859217bde77c78b7d74a skodak committed Dec 6, 2008
Showing with 67 additions and 1 deletion.
  1. +20 −0 course/edit_form.php
  2. +28 −0 enrol/manual/config.html
  3. +8 −0 enrol/manual/enrol.php
  4. +9 −1 group/group_form.php
  5. +2 −0 lang/en_utf8/enrol_manual.php
View
20 course/edit_form.php
@@ -308,6 +308,13 @@ function definition() {
$mform->setDefault('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');
@@ -425,6 +432,8 @@ function definition_after_data() {
/// perform some extra moodle validation
function validation($data, $files) {
+ global $CFG;
+
$errors = parent::validation($data, $files);
if ($foundcourses = get_records('course', 'shortname', $data['shortname'])) {
if (!empty($data['id'])) {
@@ -445,6 +454,17 @@ function validation($data, $files) {
}
}
+ 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;
}
}
View
28 enrol/manual/config.html
@@ -31,5 +31,33 @@
</td>
</tr>
+<tr>
+ <td align="right">enrol_manual_usepasswordpolicy:</td>
+ <td>
+<?php
+ $choices = array();
+ $choices['0'] = get_string('no');
+ $choices['1'] = get_string('yes');
+ choose_from_menu ($choices, 'enrol_manual_usepasswordpolicy', $frm->enrol_manual_usepasswordpolicy, '');
+?>
+ </td><td>
+ <?php print_string('enrol_manual_usepasswordpolicy', 'enrol_manual') ?>
+ </td>
+</tr>
+
+<tr>
+ <td align="right">enrol_manual_requirekey:</td>
+ <td>
+<?php
+ $choices = array();
+ $choices['0'] = get_string('no');
+ $choices['1'] = get_string('yes');
+ choose_from_menu ($choices, 'enrol_manual_requirekey', $frm->enrol_manual_requirekey, '');
+?>
+ </td><td>
+ <?php print_string('enrol_manual_requirekey', 'enrol_manual') ?>
+ </td>
+</tr>
+
</table>
View
8 enrol/manual/enrol.php
@@ -223,6 +223,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");
}
View
10 group/group_form.php
@@ -43,7 +43,7 @@ function definition () {
}
function validation($data, $files) {
- global $COURSE;
+ global $COURSE, $CFG;
$errors = parent::validation($data, $files);
@@ -55,6 +55,14 @@ function validation($data, $files) {
}
}
+ 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);
}
View
2 lang/en_utf8/enrol_manual.php
@@ -11,6 +11,8 @@
</ul>';
$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.';
?>

0 comments on commit 1d7651e

Please sign in to comment.
Something went wrong with that request. Please try again.