function account_sync_update_user in Account Sync 6
Same name and namespace in other branches
- 7.2 account_sync.receiver.inc \account_sync_update_user()
XMLRPC callback to update the user account on /this/ drupal site.
@TODO: What do we do about deleted users?
1 string reference to 'account_sync_update_user'
- account_sync_xmlrpc in ./
account_sync.module - Implementation of hook_xmlrpc().
File
- ./
account_sync.receiver.inc, line 13 - Handler inc for receiving and updating user account data.
Code
function account_sync_update_user($server_key, $username, $edit, $account, $category, $roles) {
global $_account_sync_;
$_account_sync_ = TRUE;
// Flag to catch recursive syncing
if ($message = _account_sync_sync_in_deny($server_key, $category)) {
return $message;
}
// Find the matching account on our side of things
// @TODO: What if an account is being renamed and the renamed account
// matches an existing account on our end?
if ($username && ($my_account = user_load(array(
'name' => $username,
)))) {
// Found the account, so update it.
if (user_access('sync account', $my_account)) {
if (array_key_exists('roles', $edit)) {
$edit['roles'] = _account_sync_edit_roles($roles, $account['roles'], $my_account->roles);
}
$my_account = user_save($my_account, $edit, $category);
_account_sync_update_pass($my_account->uid, $account['pass']);
$message = array(
WATCHDOG_INFO,
'User account @account has been updated.',
array(
'@account' => $my_account->name,
),
);
watchdog('account_sync', 'User account @account has been updated by a remote server.', array(
'@account' => $my_account->name,
));
}
else {
$message = array(
WATCHDOG_ERROR,
'Not permitted to update account @account.',
array(
'@account' => $account['name'],
),
);
watchdog('account_sync', 'Remote server attempted to sync @account, but it is not in a role that can be synced', array(
'@account' => $my_account->name,
));
}
}
else {
// No account found, so create the user account
if (variable_get('account_sync_create_users', FALSE)) {
unset($account['uid']);
$user = new stdClass();
$user->uid = 0;
$account['roles'] = _account_sync_roles($roles, $account['roles']);
$my_account = user_save($user, $account);
_account_sync_update_pass($my_account->uid, $account['pass']);
$message = array(
WATCHDOG_INFO,
'User account @account created',
array(
'@account' => $my_account->name,
),
);
watchdog('account_sync', 'User account @account created by a remote server.', array(
'@account' => $my_account->name,
));
}
else {
// No account found, and don't create new accounts on this site
$message = array(
WATCHDOG_ERROR,
"Couldn't find a valid account matching @account :(",
array(
'@account' => $account['init'],
),
);
}
}
return $message;
}