Commit 886ce90c authored by Nigel McNie's avatar Nigel McNie
Browse files

Make the "email" field not required for the LDAP authentication plugin. Fixes #2244.

If users do not have an e-mail address in LDAP, they will be required to set one when they log in.

This bug fixed thanks to Howard Miller and Glasgow University.
parent 5da665de
...@@ -553,7 +553,6 @@ class PluginAuthLdap extends PluginAuth { ...@@ -553,7 +553,6 @@ class PluginAuthLdap extends PluginAuth {
'title' => get_string('ldapfieldforemail', 'auth.ldap'), 'title' => get_string('ldapfieldforemail', 'auth.ldap'),
'defaultvalue' => self::$default_config['emailfield'], 'defaultvalue' => self::$default_config['emailfield'],
'help' => true, 'help' => true,
'rules' => array('required' => true),
), ),
); );
......
...@@ -686,10 +686,16 @@ function auth_check_required_fields() { ...@@ -686,10 +686,16 @@ function auth_check_required_fields() {
$elements = array(); $elements = array();
foreach(ArtefactTypeProfile::get_mandatory_fields() as $field => $type) { foreach(ArtefactTypeProfile::get_mandatory_fields() as $field => $type) {
if ($field == 'email' || get_profile_field($USER->get('id'), $field) != null) { if (get_profile_field($USER->get('id'), $field) != null) {
continue; continue;
} }
if ($field == 'email') {
// Use a text field for their first e-mail address, not the
// emaillist element
$type = 'text';
}
$elements[$field] = array( $elements[$field] = array(
'type' => $type, 'type' => $type,
'title' => get_string($field, 'artefact.internal'), 'title' => get_string($field, 'artefact.internal'),
...@@ -709,6 +715,10 @@ function auth_check_required_fields() { ...@@ -709,6 +715,10 @@ function auth_check_required_fields() {
$elements[$field]['options'] = getoptions_country(); $elements[$field]['options'] = getoptions_country();
$elements[$field]['defaultvalue'] = 'nz'; $elements[$field]['defaultvalue'] = 'nz';
} }
if ($field == 'email') {
$elements[$field]['rules']['email'] = true;
}
} }
if (empty($elements)) { // No mandatory fields that aren't set if (empty($elements)) { // No mandatory fields that aren't set
...@@ -1147,7 +1157,7 @@ function login_submit(Pieform $form, $values) { ...@@ -1147,7 +1157,7 @@ function login_submit(Pieform $form, $values) {
$USER->authinstance = $authinstance->id; $USER->authinstance = $authinstance->id;
$userdata = $auth->get_user_info($username); $userdata = $auth->get_user_info($username);
if (empty($userdata) || empty($userdata->email)) { if (empty($userdata)) {
throw new AuthUnknownUserException("\"$username\" is not known"); throw new AuthUnknownUserException("\"$username\" is not known");
} }
// We have the data - create the user // We have the data - create the user
...@@ -1158,7 +1168,13 @@ function login_submit(Pieform $form, $values) { ...@@ -1158,7 +1168,13 @@ function login_submit(Pieform $form, $values) {
if (isset($userdata->lastname)) { if (isset($userdata->lastname)) {
$USER->lastname = $userdata->lastname; $USER->lastname = $userdata->lastname;
} }
$USER->email = $userdata->email; if (isset($userdata->email)) {
$USER->email = $userdata->email;
}
else {
// The user will be asked to populate this when they log in.
$USER->email = null;
}
try { try {
db_begin(); db_begin();
$USER->commit(); $USER->commit();
...@@ -1168,7 +1184,9 @@ function login_submit(Pieform $form, $values) { ...@@ -1168,7 +1184,9 @@ function login_submit(Pieform $form, $values) {
if (isset($userdata->lastname)) { if (isset($userdata->lastname)) {
set_profile_field($USER->id, 'lastname', $USER->lastname); set_profile_field($USER->id, 'lastname', $USER->lastname);
} }
set_profile_field($USER->id, 'email', $USER->email); if (isset($userdata->email)) {
set_profile_field($USER->id, 'email', $USER->email);
}
if ($authinstance->institution !== 'mahara') { if ($authinstance->institution !== 'mahara') {
$USER->join_institution($authinstance->institution); $USER->join_institution($authinstance->institution);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment