function _fb_user_external_login in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.3 fb_user.module \_fb_user_external_login()
If facebook user has authorized app, and account map exists, login as the local user.
Return value
- TRUE, if user_external_login succeeds.
1 call to _fb_user_external_login()
- _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 335 - This module manages relations between local Drupal user accounts and their accounts on facebook.com.
Code
function _fb_user_external_login($account = NULL) {
$fbu = fb_facebook_user();
if (!$account) {
$account = fb_user_get_local_user($fbu, $GLOBALS['_fb_app']);
}
if ($account && $account->uid == $GLOBALS['user']->uid) {
// Already logged in.
return $account;
}
elseif ($fbu && $account && $account->uid != $GLOBALS['user']->uid && !fb_controls(FB_USER_CONTROL_NO_HONOR_MAP)) {
// Map exists. Log in as local user.
$session_id = session_id();
if (fb_verbose() === 'extreme') {
// debug
watchdog("fb_user", "fb_user_fb changing user to {$account->uid}");
}
// user_external_login() fails if already logged in, so log out first.
if ($GLOBALS['user']->uid) {
_fb_logout();
}
// user_external_login() removed in D7, no replacement. Let's hope the following works.
$GLOBALS['user'] = $account;
$account_array = (array) $account;
user_login_finalize($account_array);
// Special effort to support browsers without third-party cookies.
if (function_exists('fb_sess_regenerate_hack')) {
fb_sess_regenerate_hack();
}
if (fb_verbose() === 'extreme') {
// debug
watchdog("fb_user", "fb_user_fb changed session from {$session_id} to " . session_id());
}
// Session changed after external login. Invoking hook here allows modules to drupal_set_message().
fb_invoke(FB_USER_OP_POST_EXTERNAL_LOGIN, array(
'account' => $account,
), NULL, 'fb_user');
return $account;
}
return FALSE;
}