You are here

function fb_register_user in Drupal for Facebook 6.2

Implementation of hook_user().

Register users whenever an email address may have changed.

File

contrib/fb_register.module, line 300
This code aims to prevent duplicate accounts.

Code

function fb_register_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'delete') {
    db_query("DELETE FROM {fb_register} WHERE uid = %d", $account->uid);
  }
  elseif ($op == 'insert' || $op == 'update') {

    // Re-register on update, as mail address may have changed.
    // Register on insert is optional.
    if ($edit['mail']) {
      $hash = fb_register_email_hash($edit['mail']);
      $register_data = array(
        array(
          'email_hash' => $hash,
          'account_url' => url('user/' . $account->uid, array(
            'absolute' => TRUE,
          )),
        ),
      );
      db_query("DELETE FROM {fb_register} WHERE uid = %d", $account->uid);
      db_query("INSERT INTO {fb_register} (uid, email_hash) VALUES (%d, '%s')", $account->uid, $hash);
      $apps = fb_get_all_apps();
      foreach ($apps as $app) {
        $fb_app_data = fb_get_app_data($app);
        $fb_register_data = isset($fb_app_data['fb_register']) ? $fb_app_data['fb_register'] : array();
        if (is_array($fb_register_data) && isset($fb_register_data['register_users']) && $fb_register_data['register_users']) {
          $fb = fb_api_init($app);
          $success_data = $fb->api_client
            ->connect_registerUsers(json_encode($register_data));
          if (fb_verbose()) {
            watchdog('fb_register', '%application sent email hash for !user.  Facebook returned %num_returned successfully registered.', array(
              '%application' => $app->title,
              '!user' => l($edit['name'], 'user/' . $account->uid),
              '%num_returned' => count($success_data),
            ));
          }
        }
      }
    }
  }
}