function esi_user in ESI: Edge Side Includes 6.2
Implementation of hook_user(). For maximum cache-efficiency, the proxy must be able to identify the roles held by a user. A cookie is used which provides a consistent hash for all users who share the same roles. For security, the hash uses a random seed which is rotated (by hook_cron) at regular intervals - defaults to daily.
1 call to esi_user()
- esi_init in ./
esi.module - Implementation of hook_init().
File
- ./
esi.module, line 237 - Adds support for ESI (Edge-Side-Include) integration, allowing blocks to be\ delivered by ESI, with support for per-block cache times.
Code
function esi_user($op, &$edit, &$account, $category = NULL) {
// only respond to login/logout.
if (!($op == 'login' || $op == 'logout')) {
return;
}
// Drupal session cookies use the name 'SESS' followed by an MD5 hash.
// The role-cookie is the same, prefixes with the letter 'R'.
$cookie_params = session_get_cookie_params();
$role_cookie = $cookie_params + array(
'name' => 'R' . session_name(),
);
$user_cookie = $cookie_params + array(
'name' => 'U' . session_name(),
);
if ($op == 'login') {
require_once drupal_get_path('module', 'esi') . '/esi.inc';
$role_hash = _esi__get_roles_hash(array_keys($account->roles));
$user_hash = esi_get_user_hash($account->uid);
$lifespan = max(variable_get('esi_seed_key_rotation_interval', ESI_SEED_ROTATION_INTERVAL), ini_get('session.cookie_lifetime'));
$role_cookie += array(
'value' => $role_hash,
'expire' => time() + $lifespan,
);
$user_cookie += array(
'value' => $user_hash,
'expire' => time() + $lifespan,
);
}
else {
$role_cookie += array(
'value' => 'deleted',
'expire' => 1,
);
$user_cookie += array(
'value' => 'deleted',
'expire' => 1,
);
}
drupal_alter('esi_role_cookie', $role_cookie, $op, $account);
drupal_alter('esi_user_cookie', $user_cookie, $op, $account);
setcookie($role_cookie['name'], $role_cookie['value'], $role_cookie['expire'], $role_cookie['path'], $role_cookie['domain']);
setcookie($user_cookie['name'], $user_cookie['value'], $user_cookie['expire'], $user_cookie['path'], $user_cookie['domain']);
}