Permalink
Browse files

Fixed bug in external auth.

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...
1 parent ea77aa0 commit e3da2769b847e299f32c94fe3285a0858ce39e8c martinlanghoff committed Nov 22, 2004
Showing with 33 additions and 0 deletions.
  1. +33 −0 lib/moodlelib.php
View
@@ -864,6 +864,7 @@ function create_user_record($username, $password, $auth='') {
if (function_exists('auth_get_userinfo')) {
if ($newinfo = auth_get_userinfo($username)) {
+ $newinfo = truncate_userinfo($newinfo);
foreach ($newinfo as $key => $value){
$newuser->$key = addslashes(stripslashes($value)); // Just in case
}
@@ -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() {
global $CFG;

0 comments on commit e3da276

Please sign in to comment.