You are here

function bakery_taste_stroopwafel_cookie in Bakery Single Sign-On System 6

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

Validate update request.

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

File

./bakery.module, line 502

Code

function bakery_taste_stroopwafel_cookie() {
  $payload = $_POST['stroopwafel'];
  $valid = FALSE;
  if ($payload) {
    $cookie = unserialize(bakery_mix($payload, 0));
    $key = variable_get('bakery_key', '');
    $signature = hash_hmac('sha256', $cookie['data'] . '/' . $cookie['uid'] . '/' . $cookie['timestamp'], $key);
    if ($signature == $cookie['signature'] && $cookie['timestamp'] + variable_get('bakery_freshness', '3600') >= $_SERVER['REQUEST_TIME']) {
      $valid = TRUE;
      $_SESSION['bakery'] = unserialize($cookie['data']);
      $_SESSION['bakery']['uid'] = $cookie['uid'];
      $_SESSION['bakery']['category'] = $cookie['category'];
    }
  }
  return $valid;
}