Skip to content

Commit

Permalink
Per-auth-backend field locks support. Merged from MOODLE_15_STABLE
Browse files Browse the repository at this point in the history
 * Extended set_config()
 * Implemented get_config() which takes over $CFG loading in setup.php
 * admin/auth.php has special handling if post vars starting in pluginconfig_
 * admin/auth.php print_auth_lock_options() prints a form fragment -- being called from most plugins now
 *  user/edit.php follows the new convention when locking down fields, both javascript UI and on POST.
 * admin/auth: More solid checking for auth GET/POST var.
 * admin/auth: print_auth_lock_options() now handles user field mapping options for LDAP and similar modules
 * admin/auth: user mapping options have moved to config_plugins table
 * auth/ldap module has migrated to using new field mapping vars -- simplified config.html a lot
 * auth settings migration to config_plugins
  • Loading branch information
martinlanghoff committed Jun 2, 2005
1 parent 631bbc6 commit a408031
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 903 deletions.
111 changes: 101 additions & 10 deletions admin/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@
$config = (array)$config;
validate_form($config, $err);

// extract and sanitize the auth key explicitly
$modules = get_list_of_plugins("auth");
if (in_array($config['auth'], $modules)) {
$auth = $config['auth'];
} else {
notify("Error defining the authentication method");
}

if (count($err) == 0) {
print_header();
foreach ($config as $name => $value) {
if (! set_config($name, $value)) {
notify("Problem saving config $name as $value");
if (preg_match('/^pluginconfig_(.+?)$/', $name, $matches)) {
$plugin = "auth/$auth";
$name = $matches[1];
if (! set_config($name, $value, $plugin)) {
notify("Problem saving config $name as $value for plugin $plugin");
}
} else { // normal handling for
if (! set_config($name, $value)) {
notify("Problem saving config $name as $value");
}
}
}
redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
Expand All @@ -51,7 +67,7 @@
$options[$module] = get_string("auth_$module"."title", "auth");
}
asort($options);
if (isset($_GET['auth'])) {
if (isset($_GET['auth']) && in_array($_GET['auth'], $modules)) {
$auth = $_GET['auth'];
} else {
$auth = $config->auth;
Expand All @@ -72,13 +88,6 @@
}
$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");

foreach ($user_fields as $user_field) {
$user_field = "auth_user_$user_field";
if (! isset($config->$user_field)) {
$config->$user_field = "";
}
}

if (empty($focus)) {
$focus = "";
}
Expand Down Expand Up @@ -198,5 +207,87 @@ function validate_form(&$form, &$err) {
return;
}

//
// Good enough for most auth plugins
// but some may want a custom one if they are offering
// other options
// Note: pluginconfig_ fields have special handling.
function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {

echo '<tr><td colspan="3">';
if ($retrieveopts) {
print_heading(get_string('auth_data_mapping', 'auth'));
} else {
print_heading(get_string('auth_fieldlocks', 'auth'));
}
echo '<td/></tr>';

$lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
'unlockedifempty' => get_string('unlockedifempty', 'auth'),
'locked' => get_string('locked', 'auth'));
$updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
'onlogin' => get_string('update_onlogin', 'auth'));
$updateextoptions = array('0' => get_string('update_never', 'auth'),
'1' => get_string('update_onupdate', 'auth'));

$pluginconfig = get_config("auth/$auth");

// helptext is on a field with rowspan
if (empty($helptext)) {
$helptext = '&nbsp;';
}

foreach ($user_fields as $field) {

// Define some vars we'll work with
optional_variable($pluginconfig->{"field_map_$field"}, '');
optional_variable($pluginconfig->{"field_updatelocal_$field"}, '');
optional_variable($pluginconfig->{"field_updateremote_$field"}, '');
optional_variable($pluginconfig->{"field_lock_$field"}, '');

// define the fieldname we display to the user
$fieldname = $field;
if ($fieldname === 'lang') {
$fieldname = get_string('language');
} elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
$fieldname = get_string($matches[1]) . ' ' . $matches[2];
} else {
$fieldname = get_string($fieldname);
}

echo '<tr valign="top"><td align="right">';
echo $fieldname;
echo '</td><td>';

if ($retrieveopts) {
$varname = 'field_map_' . $field;

echo "<input name=\"pluginconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\">";
echo '<div align="right">';
echo get_string('auth_updatelocal', 'auth') . '&nbsp;&nbsp;';
choose_from_menu($updatelocaloptions, "pluginconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
echo '<br />';
if ($updateopts) {
echo get_string('auth_updateremote', 'auth') . '&nbsp;&nbsp;';
'&nbsp;&nbsp;';
choose_from_menu($updateextoptions, "pluginconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
echo '<br />';


}
echo get_string('auth_fieldlock', 'auth') . '&nbsp;&nbsp;';
choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
echo '</div>';
} else {
choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
}
echo '</td>';
if (!empty($helptext)) {
echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
$helptext = '';
}
echo '</tr>';
}
}

?>
89 changes: 1 addition & 88 deletions auth/db/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,94 +135,7 @@
</td>
</tr>


<tr>
<td align="right"><?php print_string("firstname") ?>:</td>
<td>
<input name="auth_user_firstname" type="text" size="30" value="<?php echo $config->auth_user_firstname?>" />
</td>
<td rowspan="12" valign="middle">
<?php print_string("auth_dbextrafields","auth") ?>
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("lastname") ?>:</td>
<td>
<input name="auth_user_lastname" type="text" size="30" value="<?php echo $config->auth_user_lastname?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("email") ?>:</td>
<td>
<input name="auth_user_email" type="text" size="30" value="<?php echo $config->auth_user_email?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("phone") ?> 1:</td>
<td>
<input name="auth_user_phone1" type="text" size="30" value="<?php echo $config->auth_user_phone1?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("phone") ?> 2:</td>
<td>
<input name="auth_user_phone2" type="text" size="30" value="<?php echo $config->auth_user_phone2?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("department") ?>:</td>
<td>
<input name="auth_user_department" type="text" size="30" value="<?php echo $config->auth_user_department?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("address") ?>:</td>
<td>
<input name="auth_user_address" type="text" size="30" value="<?php echo $config->auth_user_address?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("city") ?>:</td>
<td>
<input name="auth_user_city" type="text" size="30" value="<?php echo $config->auth_user_city?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("country") ?>:</td>
<td>
<input name="auth_user_country" type="text" size="30" value="<?php echo $config->auth_user_country?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("description") ?>:</td>
<td>
<input name="auth_user_description" type="text" size="30" value="<?php echo $config->auth_user_description?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("idnumber") ?>:</td>
<td>
<input name="auth_user_idnumber" type="text" size="30" value="<?php echo $config->auth_user_idnumber?>" />
</td>
</tr>

<tr valign="top">
<td align="right"><?php print_string("language") ?>:</td>
<td>
<input name="auth_user_lang" type="text" size="30" value="<?php echo $config->auth_user_lang?>" />
</td>
</tr>

<?php print_auth_lock_options($auth, $user_fields, get_string("auth_dbextrafields","auth"), true, false); ?>

<tr valign="top">
<td align="right"><?php print_string("instructions", "auth") ?>:</td>
Expand Down
7 changes: 5 additions & 2 deletions auth/db/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ function auth_get_userinfo($username){

$config = (array) $CFG;

$pcfg = get_config('auth/db');
$pcfg = (array) $pcfg;

ADOLoadCode($CFG->auth_dbtype);
$authdb = &ADONewConnection();
$authdb->PConnect($CFG->auth_dbhost,$CFG->auth_dbuser,$CFG->auth_dbpass,$CFG->auth_dbname);
Expand All @@ -69,8 +72,8 @@ function auth_get_userinfo($username){
$result = array();

foreach ($fields as $field) {
if ($config["auth_user_$field"]) {
if ($rs = $authdb->Execute("SELECT ".$config["auth_user_$field"]." FROM $CFG->auth_dbtable
if ($pcfg["field_map_$field"]) {
if ($rs = $authdb->Execute("SELECT ".$pcfg["field_map_$field"]." FROM $CFG->auth_dbtable
WHERE $CFG->auth_dbfielduser = '$username'")) {
if ( $rs->RecordCount() == 1 ) {
$result["$field"] = $rs->fields[0];
Expand Down
2 changes: 2 additions & 0 deletions auth/email/config.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<!-- No config needed -->
<div align="center"><?php print_string('none'); ?></div>

<?php print_auth_lock_options($auth, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false); ?>
1 change: 1 addition & 0 deletions auth/fc/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@

</tr>

<?php print_auth_lock_options($auth, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false); ?>
1 change: 1 addition & 0 deletions auth/imap/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
<?php helpbutton("text", get_string("helptext")) ?>
</td>
</tr>
<?php print_auth_lock_options($auth, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false); ?>
Loading

0 comments on commit a408031

Please sign in to comment.