Skip to content

Instantly share code, notes, and snippets.

@zuk
Created September 19, 2011 13:10
Show Gist options
  • Save zuk/1226462 to your computer and use it in GitHub Desktop.
Save zuk/1226462 to your computer and use it in GitHub Desktop.
/**
* Let Rollcall take care of asking the user for their login and password.
*/
if ($_REQUEST['token'])
$token = $_REQUEST['token'];
elseif ($_SESSION['token'])
$token = $_SESSION['token'];
else
$token = null;
$rollcall_url = 'http://rollcall.aardvark.encorelab.org';
$pest = new PestXML($rollcall_url);
if ($_SESSION['rollcall']) {
// we're already previously authenticated (see below)
$rollcall_session = $_SESSION['rollcall'];
} elseif (!$token) {
$current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
// redirect to Rollcall for authentication
header('Location: '.$rollcall_url.'/login?destination='.$current_url);
exit();
} else {
// validate the token
$rollcall_session = $pest->get('/login/validate_token/'.$token.'.xml')
// assuming the $token was valid, $session now contains the session
// data along with the user's account information...
// you might want to put this under a $_SESSION variable and
// check for that next time to avoid re-authenticating on every
// request.
$_SESSION['rollcall'] = $rollcall_session;
}
/**
* You ask the user for login/password yourself. This assumes that
* your login form was submitted and that the credentials are now under
* $_REQUEST['login'] and $_REQUEST['password'].
*/
$rollcall_url = 'http://rollcall.aardvark.encorelab.org';
$pest = new PestXML($rollcall_url);
if ($_SESSION['rollcall']) {
// we're already previously authenticated (see below)
$rollcall_session = $_SESSION['rollcall'];
} else {
// validate the token
$rollcall_session = $pest->post('/login', array(
'session' => array('login' => $_REQUEST['login'], 'password' => $_REQUEST['password'])
))
// assuming the $credentials were valid, $session now contains the session
// data along with the user's account information...
// you might want to put this under a $_SESSION variable and
// check for that next time to avoid re-authenticating on every
// request.
$_SESSION['rollcall'] = $rollcall_session;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment