function tokenauth_init in Token authentication 5
Same name and namespace in other branches
- 6.2 tokenauth.module \tokenauth_init()
- 6 tokenauth.module \tokenauth_init()
Implementation of hook_init().
File
- ./
tokenauth.module, line 228
Code
function tokenauth_init() {
global $user;
// Process any provided token and log in user
if (!$user->uid && $_REQUEST['token'] && tokenauth_allowed_pages($_GET['q']) && function_exists('drupal_set_content')) {
$sql = "SELECT tt.uid FROM {tokenauth_tokens} tt INNER JOIN {users} u ON tt.uid = u.uid WHERE token = '%s' AND u.status != 0";
if ($uid = db_result(db_query($sql, $_REQUEST['token']))) {
$user = user_load(array(
'uid' => $uid,
));
$_SESSION['tokenauth_auth'] = TRUE;
// Just store the fact that this user authenticated via token
}
else {
// Supplied an invalid token
drupal_access_denied();
exit;
}
}
}