Skip to content

Commit

Permalink
Fixed bug in external auth.
Browse files Browse the repository at this point in the history
Added truncate_userinfo() which ensures data from external auth fits in moodle database fields. Before, user records that did not fit would be dropped silently.

This is a merge from arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-172
  • Loading branch information
martinlanghoff committed Nov 22, 2004
1 parent ea77aa0 commit e3da276
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/moodlelib.php
Expand Up @@ -864,6 +864,7 @@ function create_user_record($username, $password, $auth='') {


if (function_exists('auth_get_userinfo')) { if (function_exists('auth_get_userinfo')) {
if ($newinfo = auth_get_userinfo($username)) { if ($newinfo = auth_get_userinfo($username)) {
$newinfo = truncate_userinfo($newinfo);
foreach ($newinfo as $key => $value){ foreach ($newinfo as $key => $value){
$newuser->$key = addslashes(stripslashes($value)); // Just in case $newuser->$key = addslashes(stripslashes($value)); // Just in case
} }
Expand Down Expand Up @@ -891,6 +892,38 @@ function create_user_record($username, $password, $auth='') {
} }




function truncate_userinfo($info) {
/// will truncate userinfo as it comes from auth_get_userinfo (from external auth)
/// which may have large fields

// define the limits
$limit = array(
'username' => 100,
'idnumber' => 12,
'firstname' => 20,
'lastname' => 20,
'email' => 100,
'icq' => 15,
'phone1' => 20,
'phone2' => 20,
'institution' => 40,
'department' => 30,
'address' => 70,
'city' => 20,
'country' => 2,
'url' => 255,
);

// apply where needed
foreach (array_keys($info) as $key) {
if (!empty($limit[$key])) {
$info[$key] = substr($info[$key],0, $limit[$key]);
}
}

return $info;
}

function guest_user() { function guest_user() {
global $CFG; global $CFG;


Expand Down

0 comments on commit e3da276

Please sign in to comment.