cvs: pear /Perm_LiveUser/examples example_medium.php
| From: | Arnaud Limbourg | Date: | Sat, 07 Dec 2002 18:19:00 +0000 |
| Subject: | cvs: pear /Perm_LiveUser/examples example_medium.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7770@lists.php.net to get a copy of this message | ||
arnaud Sat Dec 7 13:19:00 2002 EDT
Modified files:
/pear/Perm_LiveUser/examples example_medium.php
Log:
* improved it somewhat
Index: pear/Perm_LiveUser/examples/example_medium.php
diff -u pear/Perm_LiveUser/examples/example_medium.php:1.1
pear/Perm_LiveUser/examples/example_medium.php:1.2
--- pear/Perm_LiveUser/examples/example_medium.php:1.1 Sat Dec 7 13:10:09 2002
+++ pear/Perm_LiveUser/examples/example_medium.php Sat Dec 7 13:19:00 2002
@@ -1,27 +1,26 @@
<?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...
- *
- **/
+ *
+ * This example is intended to be used with the DB_Medium Perm driver.
+ *
+ */
error_reporting(E_ALL);
-ini_set("include_path", '.;c:/www/ext/pear');
-
-
-define('LIVEUSER_AREA_COFFEEMAKER', 1);
-define('LIVEUSER_RIGHT_MAKE_COFFEE', 1);
+//ini_set("include_path", '.;/path/to/pear');
-//echo ini_get('include_path');
+define('LIVEUSER_AREA_COFFEEMAKER', 1);
+define('LIVEUSER_RIGHT_MAKE_COFFEE', 1);
+define('LIVEUSER_RIGHT_DRINK_COFFEE', 2);
// Get LoginManager class definition
-require_once('LoginManager.php');
+require_once 'LoginManager.php';
// The error handling stuff is not needed and used only for debugging
// while LiveUser is not yet mature
@@ -34,17 +33,13 @@
// 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 = new LoginManager('demoConf.xml');
+// this sets a callback function if the user hasn't logged in yet
$LoMa->setLoginFunction('testLogin');
/**
- *
- *
- * @return
+ * Example callback function on logging in
*/
function testLogin()
{
@@ -52,7 +47,6 @@
exit();
} // end func testLogin
-
// Trigger the login process
$LoMa->init();
@@ -74,10 +68,16 @@
// 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!";
+ echo 'the right to make coffee !';
} else {
echo "Your coffee tastes so bad, I won't allow you to make some";
}
+
+ if ($level = $LoMa->checkRight(LIVEUSER_AREA_COFFEEMAKER, LIVEUSER_RIGHT_DRINK_COFFEE)) {
+ echo 'Yey ! You can even drink some coffee';
+ } else {
+ echo 'Well, sorry dude, you cannot drink in here';
+ }
}
// Just some more debug output with no further relevance
@@ -91,6 +91,4 @@
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));
?>