You are here

function janrain_capture_sync_account in Janrain Registration 7.4

Same name and namespace in other branches
  1. 7 janrain_capture.module \janrain_capture_sync_account()
  2. 7.2 janrain_capture.module \janrain_capture_sync_account()
  3. 7.3 janrain_capture.module \janrain_capture_sync_account()

Modifies the user account with values from the Janrain Capture profile array.

Invokes a hook to allow other modules to modify the account as well.

Parameters

$account: The account object to modify with values from the Janrain Capture profile

array $profile: The Janrain Capture profile array.

5 calls to janrain_capture_sync_account()
JanrainCaptureMappingTestCase::testFieldApiMapping in janrain_capture_mapping/tests/janrain_capture_mapping.test
JanrainCaptureMappingTestCase::testPropertyMapping in janrain_capture_mapping/tests/janrain_capture_mapping.test
Create some field mappings through the UI and ensure that they work.
janrain_capture_admin_signin in includes/janrain_capture.endpoints.inc
Callback to show a Drupal login block to verify that a user is an admin
janrain_capture_oauth in includes/janrain_capture.endpoints.inc
Callback for the janrain_capture/oauth menu item. This serves as the redirect_uri Capture redirects the user to and performs the authentication.
janrain_capture_profile_sync in includes/janrain_capture.endpoints.inc
Callback for the janrain_capture/profile_sync menu item. Retrieves the most recent data from Capture and stores values locally.

File

./janrain_capture.module, line 673
This module implements authentication endpoints for Janrain Capture.

Code

function janrain_capture_sync_account($account, $profile) {
  $ver = variable_get('janrain_capture_ver', JANRAIN_CAPTURE_VERSION_DEFAULT);
  $janrain_capture_fields = $ver == JANRAIN_CAPTURE_VERSION_LEGACY ? variable_get('janrain_capture_fields', array()) : variable_get('janrain_capture_fields2', array());
  if (!isset($janrain_capture_fields['capture_no_email']) || !$janrain_capture_fields['capture_no_email']) {
    $account->mail = $profile['email'];
  }

  // Set the profile email address as the default username - this can be overridden
  // either by implementing the janrain_capture_profile_sync hook or using the mapping
  // submodule.
  if (!$account->name) {
    $account->name = $profile['uuid'];
  }

  // Set the uuid field value from the Capture uuid. Hardcoding LANGUAGE_NONE here
  // should be ok as the field is not translatable.
  $account->field_janrain_capture_uuid[LANGUAGE_NONE][0]['value'] = $profile['uuid'];

  // Map the profile pic if configured to do so. This requires special handling.
  if (isset($janrain_capture_fields['capture_map_profile_pic']) && $janrain_capture_fields['capture_map_profile_pic']) {
    if (!empty($profile['photos'])) {
      $preferred = isset($janrain_capture_fields['capture_preferred_photo_variant']) ? $janrain_capture_fields['capture_preferred_photo_variant'] : 'small';
      $found = NULL;
      foreach ($profile['photos'] as $variant) {
        if ($variant['type'] == $preferred) {
          $found = $variant;
          break;
        }
        else {
          if ($variant['type'] == 'other') {
            $found = $variant;
          }
        }
      }
      if ($found != NULL) {
        _janrain_capture_update_picture($account, $found);
      }
      else {
        watchdog('janrain_capture', 'No suitable user picture found in the Capture profile', array(), WATCHDOG_WARNING);
      }
    }
    elseif (!empty($account->picture)) {

      // We have a local picture, but picture was removed on server. Delete!
      $account->picture = new stdClass();
      db_delete('janrain_capture_photos')
        ->condition('uid', $account->uid)
        ->execute();
    }
  }
  module_invoke_all('janrain_capture_profile_sync', $account, $profile);
}