You are here

function bakery_login_return in Bakery Single Sign-On System 6.2

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

Custom return for errors during slave login process.

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

File

./bakery.module, line 849

Code

function bakery_login_return() {
  $cookie = bakery_taste_oatmeal_cookie();
  if ($cookie) {

    // Make sure we always have a default query key.
    $cookie['data'] += array(
      'query' => array(),
    );

    // Valid cookie, now destroy it.
    _bakery_eat_cookie('OATMEAL');
    $errors = $cookie['data']['errors'];
    if (!empty($errors)) {
      if (!empty($errors['incorrect-credentials'])) {
        drupal_set_message(t('Sorry, unrecognized username or password.'), 'error');
      }
      elseif (!empty($errors['name'])) {

        // In case an attacker got the hash we filter the argument here to avoid
        // exposing a XSS vector.
        drupal_set_message(filter_xss($errors['name']), 'error');
      }
    }

    // Prepare the url query array to pass to drupal_goto().
    $query = $cookie['data']['query'];
    if (empty($cookie['data']['destination'])) {
      drupal_goto('user', $query);
    }
    else {
      $_REQUEST['destination'] = $cookie['data']['destination'];
      drupal_goto('', $query);
    }
  }
  elseif (user_is_logged_in()) {
    drupal_goto();
  }
  drupal_access_denied();
}