Commit 4af02f69 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Store original & new usernames for sso-in users

parent 33dfe60b
......@@ -159,7 +159,7 @@ function fetch_user_image($username) {
}
try {
$user = new User;
$user->find_by_instanceid_username($authinstance->id, $username);
$user->find_by_instanceid_username($authinstance->id, $username, true);
$candidates[$user->id] = $user;
} catch (Exception $e) {
// we don't care
......
......@@ -124,7 +124,7 @@ class User {
/**
*
*/
public function find_by_instanceid_username($instanceid, $username) {
public function find_by_instanceid_username($instanceid, $username, $remoteuser=false) {
if (!is_numeric($instanceid) || $instanceid < 0) {
throw new InvalidArgumentException('parameter must be a positive integer to create a User object');
......@@ -134,16 +134,30 @@ class User {
$instanceid = $parentid;
}
$sql = 'SELECT
*,
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
{usr}
WHERE
LOWER(username) = ? AND
authinstance = ?';
if ($remoteuser) {
$sql = 'SELECT
u.*,
' . db_format_tsfield('u.expiry', 'expiry') . ',
' . db_format_tsfield('u.lastlogin', 'lastlogin') . ',
' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . '
FROM {usr} u
INNER JOIN {auth_remote_user} r ON u.id = r.localusr
WHERE
LOWER(r.remoteusername) = ? AND
r.authinstance = ?';
} else {
$sql = 'SELECT
*,
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
{usr}
WHERE
LOWER(username) = ? AND
authinstance = ?';
}
$user = get_record_sql($sql, array($username, $instanceid));
......
......@@ -144,7 +144,7 @@ class AuthXmlrpc extends Auth {
// Retrieve a $user object. If that fails, create a blank one.
try {
$user = new User;
$user->find_by_instanceid_username($this->instanceid, $remoteuser->username);
$user->find_by_instanceid_username($this->instanceid, $remoteuser->username, true);
if ('1' == $this->config['updateuserinfoonlogin']) {
$update = true;
}
......@@ -161,7 +161,6 @@ class AuthXmlrpc extends Auth {
if ($create) {
$user->username = $remoteuser->username;
$user->passwordchange = 1;
$user->active = 1;
$user->deleted = 0;
......@@ -180,8 +179,17 @@ class AuthXmlrpc extends Auth {
//TODO: import institution's per-user-quota?:
//$user->quota = $userrecord->quota;
$user->authinstance = empty($this->config['parent']) ? $this->instanceid : $this->parent;
db_begin();
$user->username = get_new_username($remoteuser->username);
$user->commit();
insert_record('auth_remote_user', (object) array(
'authinstance' => $user->authinstance,
'remoteusername' => $remoteuser->username,
'localusr' => $user->id,
));
$user->join_institution($peer->institution);
set_profile_field($user->id, 'firstname', $user->firstname);
......@@ -197,6 +205,7 @@ class AuthXmlrpc extends Auth {
$userobj = $user->to_stdclass();
$userarray = (array)$userobj;
handle_event('createuser', $userarray);
db_commit();
} elseif ($update) {
......@@ -228,7 +237,7 @@ class AuthXmlrpc extends Auth {
if ($create || $update) {
$client->set_method('auth/mnet/auth.php/fetch_user_image')
->add_param($user->username)
->add_param($remoteuser->username)
->send($remotewwwroot);
$imageobject = (object)$client->response;
......
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