function fb_register_fb in Drupal for Facebook 6.2
Implementation of hook_fb(). Here we customize the behavior of Drupal for Facebook.
Here we detect whether the user has previously been registered. If so, we map the facebook account to our local account.
File
- contrib/
fb_register.module, line 350 - This code aims to prevent duplicate accounts.
Code
function fb_register_fb($op, $data, &$return) {
if ($op == FB_APP_OP_EVENT) {
if ($data['event_type'] == FB_APP_EVENT_POST_AUTHORIZE) {
// User has authorized the application.
$fbu = fb_facebook_user();
$info = fb_users_getInfo(array(
$fbu,
));
if (is_array($info[0]['email_hashes'])) {
$result = db_query("SELECT * FROM {fb_register} WHERE email_hash IN (" . db_placeholders($info[0]['email_hashes'], 'varchar') . ")", $info[0]['email_hashes']);
if ($d = db_fetch_object($result)) {
// We found a mapping to a local user.
$account = user_load(array(
'uid' => $d->uid,
));
list($module, $authname) = _fb_user_get_authmap($data['fb_app'], $fbu);
user_set_authmaps($account, array(
$module => $authname,
));
if (fb_verbose()) {
watchdog('fb_register', 'Mapping facebook %fbu to local account !user', array(
'%fbu' => $fbu,
'!user' => l($account->name, 'user/' . $account->uid),
));
}
}
}
}
}
}