You are here

function bakery_profile_user_update in Bakery Single Sign-On System 7.4

Implements hook_user_update().

File

./bakery_profile.module, line 46

Code

function bakery_profile_user_update(&$edit, $account, $category) {
  global $user;

  // We need to push changes.
  if (variable_get('bakery_is_master', 0) && isset($_SESSION['bakery'])) {
    $type = 'stroopwafel';
    $key = variable_get('bakery_key', '');
    $payload['data'] = serialize($_SESSION['bakery']);
    $payload['timestamp'] = $_SERVER['REQUEST_TIME'];
    $payload['uid'] = $account->uid;
    $payload['category'] = $category;
    $payload['type'] = $type;
    $data = bakery_bake_data($payload);

    // Respond with signed account information.
    $payload = drupal_http_build_query(array(
      $type => $data,
    ));
    unset($_SESSION['bakery']);

    // Now, update the slaves.
    $slaves = variable_get('bakery_slaves', array());
    foreach ($slaves as $slave) {
      $options = array(
        'headers' => array(
          'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
        ),
        'method' => 'POST',
        'data' => $payload,
      );
      $result = drupal_http_request($slave . 'bakery/update', $options);
      if ($result->code != 200) {
        drupal_set_message(t('Error %error for site at %url', array(
          '%error' => $result->code . ' ' . $result->error,
          '%url' => $slave,
        )));
      }
      else {
        drupal_set_message($result->data);

        // TODO: Roll back the change.
      }
    }
  }
}