cvs: pear /Perm_LiveUser/examples example_medium.php
| From: | Arnaud Limbourg | Date: | Sat, 07 Dec 2002 18:10:09 +0000 |
| Subject: | cvs: pear /Perm_LiveUser/examples example_medium.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7769@lists.php.net to get a copy of this message | ||
arnaud Sat Dec 7 13:10:09 2002 EDT
Added files:
/pear/Perm_LiveUser/examples example_medium.php
Log:
* a wee example for DB_Medium
# does not do much, has to be improved
Index: pear/Perm_LiveUser/examples/example_medium.php
+++ pear/Perm_LiveUser/examples/example_medium.php
<?php
/**
* Test for the LoginManager class
* ===============================
*
* This example sets up an authorization system using the LoginManager
* class. You don't have to use this to use the LiveUser class(es), but
* this way you don't need to take care of the login-process, storing
* the user object in a session and more...
*
**/
error_reporting(E_ALL);
ini_set("include_path", '.;c:/www/ext/pear');
define('LIVEUSER_AREA_COFFEEMAKER', 1);
define('LIVEUSER_RIGHT_MAKE_COFFEE', 1);
//echo ini_get('include_path');
// Get LoginManager class definition
require_once('LoginManager.php');
// The error handling stuff is not needed and used only for debugging
// while LiveUser is not yet mature
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "eHandler");
function eHandler($errObj)
{
echo("<hr><font
color=red>".$errObj->getMessage().':<br>'.$errObj->getUserinfo()."</font><hr>");
}
// Create new LoginManager object, providing an XML file that contains
// configuration information
$LoMa = new LoginManager("demoConf.xml");
// Set the name of our application
$LoMa->setApplication("DemoApp");
$LoMa->setLoginFunction('testLogin');
/**
*
*
* @return
*/
function testLogin()
{
header("Location: example.htm");
exit();
} // end func testLogin
// Trigger the login process
$LoMa->init();
// Check if the user has logged in successfully
if (!$LoMa->isLoggedIn()) {
// The user couldn't login, so let's check if the reason was that
// he's not yet been declared "valid" by an administrator.
if ($LoMa->isInactive()) {
echo "Sorry kid, but one of our admins has yet to approve ";
echo "your user status. Please be patient. Don't call us - ";
echo "we'll call you.";
} else {
echo "Sorry, we can't let you in. Check if the spelling of ";
echo "your handle and password is correct.";
}
} else {
// Okay, he's in. Now let's display some content dependent of
// his access rights in our application. Let's pretend the current
// AuthArea of our application is the Coffeemaker section...
if ($level = $LoMa->checkRight(LIVEUSER_AREA_COFFEEMAKER, LIVEUSER_RIGHT_MAKE_COFFEE)) {
echo "Congrats, you're in the Coffeemaker section and have ";
echo "the right to make coffee at level $level!";
} else {
echo "Your coffee tastes so bad, I won't allow you to make some";
}
}
// Just some more debug output with no further relevance
echo "<hr><pre>";
print_r($LoMa);
echo "<hr>";
print_r($_SESSION);
echo "<hr>";
print_r($_POST);
echo "</pre>";
echo "<br>User Type:";
print_r($LoMa->_perm->user_type);
//echo "<br>Checking Level:";
//print_r($LoMa->checkRightLevel(LIVEUSER_AREA_COFFEEMAKER, LIVEUSER_RIGHT_MAKE_COFFEE, 2, 2));
?>