Skip to content

Instantly share code, notes, and snippets.

@sunnywalker
Created June 30, 2012 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnywalker/3021610 to your computer and use it in GitHub Desktop.
Save sunnywalker/3021610 to your computer and use it in GitHub Desktop.
Using the UHLoginService PHP class
<?php
// assume session_start(); somewhere prior to this
//set the user level based on the uh username (could also check a database or something)
//this function, if it exists, will get called by the class
function getUserLevelByName($uh_username) {
return in_array($uh_username, array('swalker', 'jvelasqu')) ? 100 : 10; //these people get 100 user level, everybody else gets a 10
}
//include the php class
require_once('/path/to/includes/_UHLoginService.php');
//set up the app (used for session variables and login/logout forwarding
$login = new UHLoginService('NameOfApp', '/path/to/app/');
//require 'hawcc' campus affiliation
$login->setRestriction('campus', 'hawcc');
//require 'staff' affiliation
$login->setRestriction('affiliation', 'staff');
//handle the login/logout ticketing to/from the CAS
$login->processQueue();
//make sure they've successfully logged in (mandatory login)
$login->checkLogin();
//... elsewhere in the page
if ($login->isLevel(100)) {
//this stuff is for admins only, with 100 user level
}
//and to allow a logout
echo '<a href="./?logout">Log out</a>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment