You are here

function bakery_eat_stroopwafel_cookie in Bakery Single Sign-On System 6.2

Same name and namespace in other branches
  1. 6 bakery.module \bakery_eat_stroopwafel_cookie()
  2. 7.2 bakery.module \bakery_eat_stroopwafel_cookie()

Menu callback, invoked on the slave

1 string reference to 'bakery_eat_stroopwafel_cookie'
bakery_menu in ./bakery.module
Implementation of hook_menu().

File

./bakery.module, line 1217

Code

function bakery_eat_stroopwafel_cookie() {

  // the session got set during validation
  $stroopwafel = $_SESSION['bakery'];
  unset($_SESSION['bakery']);
  $init = _bakery_init_field($stroopwafel['uid']);

  // check if the user exists.
  $account = user_load(array(
    'init' => $init,
  ));
  if (!$account) {

    // user not present
    $message = t('Account not found on %slave.', array(
      '%slave' => variable_get('site_name', ''),
    ));
  }
  else {
    drupal_set_header('X-Drupal-bakery-UID: ' . $account->uid);

    // If profile field is enabled we manually save profile fields along the way.
    $status = user_save($account, bakery_prepare_fields($stroopwafel, $account));
    if ($status === FALSE) {
      watchdog('bakery', 'User update from name %name_old to %name_new, mail %mail_old to %mail_new failed.', array(
        '%name_old' => $account->name,
        '%name_new' => $stroopwafel['name'],
        '%mail_old' => $account->mail,
        '%mail_new' => $stroopwafel['mail'],
      ), WATCHDOG_ERROR);
      $message = t('There was a problem updating your account on %slave. Please contact the administrator.', array(
        '%slave' => variable_get('site_name', ''),
      ));
      header('HTTP/1.1 409 Conflict');
    }
    else {
      watchdog('bakery', 'user updated name %name_old to %name_new, mail %mail_old to %mail_new.', array(
        '%name_old' => $account->name,
        '%name_new' => $stroopwafel['name'],
        '%mail_old' => $account->mail,
        '%mail_new' => $stroopwafel['mail'],
      ));
      $message = t('Successfully updated account on %slave.', array(
        '%slave' => variable_get('site_name', ''),
      ));

      // Invoke hook_bakery_receive().
      module_invoke_all('bakery_receive', $account, $stroopwafel);
    }
  }
  module_invoke_all('exit');
  print $message;
  exit;
}