function _fb_user_process_new_token in Drupal for Facebook 7.4
2 calls to _fb_user_process_new_token()
- fb_user_fb in ./fb_user.module
- Implements hook_fb().
- fb_user_user_login in ./fb_user.module
- Implements hook_user_login().
File
- ./fb_user.module, line 175
- This module manages relations between local Drupal user accounts
and their accounts on facebook.com.
Code
function _fb_user_process_new_token($token) {
if (user_access(FB_USER_PERM_NEVER_MAP)) {
if (user_access('access administration pages')) {
drupal_set_message(t('fb_user.module ignoring facebook connect for administrator account.'));
}
return;
}
$map_policy = variable_get(FB_USER_VAR_MAP_POLICY, array(
FB_USER_OPTION_MAP_LOGGED_IN,
FB_USER_OPTION_MAP_EMAIL,
));
$create_policy = variable_get(FB_USER_VAR_CREATE_POLICY, FB_USER_OPTION_CREATE_NEVER);
try {
$me = fb_graph('me', $token);
$fbu = $me['id'];
$fb_user_data = db_query("SELECT * FROM {fb_user} WHERE fbu=:fbu", array(
':fbu' => $fbu,
))
->fetchAssoc();
if ($uid = $fb_user_data['uid']) {
if ($uid != $GLOBALS['user']->uid) {
if ($account = user_load($uid)) {
_fb_user_set_current_user($account);
return;
}
}
}
else {
if (in_array(FB_USER_OPTION_MAP_EMAIL, $map_policy)) {
if (!empty($me['email'])) {
if ($account = user_load_by_mail($me['email'])) {
_fb_user_set_map($account, $fbu);
_fb_user_set_current_user($account);
return;
}
}
}
if ($uid = $GLOBALS['user']->uid) {
if (in_array(FB_USER_OPTION_MAP_LOGGED_IN, $map_policy)) {
_fb_user_set_map($GLOBALS['user'], $fbu);
return;
}
}
else {
if ($create_policy == FB_USER_OPTION_CREATE_LOGIN) {
if ($account = _fb_user_create_local_account($me)) {
_fb_user_set_current_user($account);
}
return;
}
}
}
} catch (Exception $e) {
fb_log_exception($e, t('fb_user.module failed to process a new token.'));
}
}