function _fb_user_create_local_account in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.3 fb_user.module \_fb_user_create_local_account()
- 7.4 fb_user.module \_fb_user_create_local_account()
Helper function to create local account for the currently authorized user.
1 call to _fb_user_create_local_account()
- _fb_user_process_authorized_user in ./
fb_user.module - Create local account or account map for a facebook user who has authorized the application.
File
- ./
fb_user.module, line 425 - This module manages relations between local Drupal user accounts and their accounts on facebook.com.
Code
function _fb_user_create_local_account() {
$fbu = fb_facebook_user();
$account = fb_user_get_local_user($fbu);
if ($fbu && !$account && !fb_controls(FB_USER_CONTROL_NO_CREATE_ACCOUNT)) {
$config = _fb_user_get_config($GLOBALS['_fb_app']);
// Establish user name.
// Case 1: use name from FB
// Case 2: create a unique user name ourselves
// Which we use is determined by the setting at
// admin/structure/fb/fb_user
if (variable_get(FB_USER_VAR_USERNAME_STYLE, FB_USER_OPTION_USERNAME_FBU) == FB_USER_OPTION_USERNAME_FULL) {
try {
// Use fb->api() rather than fb_users_getInfo(). Later fails to learn name on test accounts.
$info = $GLOBALS['_fb']
->api($fbu);
$username = $info['name'];
} catch (Exception $e) {
fb_log_exception($e, t('Failed to learn full name of new user'), $GLOBALS['_fb']);
}
}
else {
// Create a name that is likely to be unique.
$username = "{$fbu}@facebook";
}
if ($config['new_user_rid']) {
$roles = array(
$config['new_user_rid'] => TRUE,
);
}
else {
$roles = array();
}
$account = fb_user_create_local_user($GLOBALS['_fb'], $GLOBALS['_fb_app'], $fbu, array(
'name' => $username,
'roles' => $roles,
));
watchdog('fb_user', t("Created new user !username for application %app", array(
'!username' => l($account->name, 'user/' . $account->uid),
'%app' => $GLOBALS['_fb_app']->label,
)));
return $account;
}
return FALSE;
}