cvs: pear /Perm_LiveUser/examples/example1 example.php /Perm_LiveUser/examples/example2 example.php /Perm_LiveUser/examples/example3 area51.php
coffeemaker.php conf.php testarea.php /Perm_LiveUser/examples/example4 demodata.sql finish.inc.php main.inc.php news_change.php news_new.php
| From: | Bj�rn Kraus | Date: | Thu, 05 Jun 2003 16:48:43 +0000 |
| Subject: | cvs: pear /Perm_LiveUser/examples/example1 example.php /Perm_LiveUser/examples/example2 example.php /Perm_LiveUser/examples/example3 area51.php coffeemaker.php conf.php testarea.php /Perm_LiveUser/examples/example4 demodata.sql finish.inc.php main.inc.php news_change.php news_new.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-10713@lists.php.net to get a copy of this message | ||
krausbn Thu Jun 5 12:48:43 2003 EDT
Modified files:
/pear/Perm_LiveUser/examples/example1 example.php
/pear/Perm_LiveUser/examples/example2 example.php
/pear/Perm_LiveUser/examples/example3 area51.php coffeemaker.php
conf.php testarea.php
/pear/Perm_LiveUser/examples/example4 demodata.sql finish.inc.php
main.inc.php news_change.php
news_new.php
Log:
Updated examples for LiveUser 0.7
Index: pear/Perm_LiveUser/examples/example1/example.php diff -u pear/Perm_LiveUser/examples/example1/example.php:1.1 pear/Perm_LiveUser/examples/example1/example.php:1.2 --- pear/Perm_LiveUser/examples/example1/example.php:1.1 Sat Mar 15 09:37:46 2003 +++ pear/Perm_LiveUser/examples/example1/example.php Thu Jun 5 12:48:43 2003 @@ -12,7 +12,7 @@ * No permission management is supported. * * @author Björn Kraus <krausbn@php.net> - * @version $Id: example.php,v 1.1 2003/03/15 14:37:46 krausbn Exp $ + * @version $Id: example.php,v 1.2 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -21,8 +21,11 @@ $tmp[(count($tmp)-1)] = 'pear'; ini_set('include_path', implode('/', $tmp)); +// Include PEAR +require_once 'PEAR.php'; + // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -38,10 +41,14 @@ // You need to copy the demoConf.xml and the Auth_XML.xml in the same dir // and set in demoConf.xml the right auth container. Perm containers are // not supported. -$LoMa = new LoginManager('conf.xml'); +$LU = LiveUser::create('conf.xml'); + +// This sets a callback function if the user hasn't logged in yet +$LU->setLoginFunction('testLogin'); -// this sets a callback function if the user hasn't logged in yet -$LoMa->setLoginFunction('testLogin'); +// This sets a callback function when the user tries to logout. +// In our case it's ok to use the same function. +$LU->setLogoutFunction('testLogin'); /** * Example callback function on logging in @@ -53,7 +60,7 @@ } // end func testLogin // Trigger the login process -$LoMa->init(); +$LU->init(); ?> <html> <head> @@ -64,10 +71,10 @@ <body bgcolor="#FFFFFF"> <?php // Check if the user has logged in successfully -if (!$LoMa->isLoggedIn()) { +if (!$LU->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()) { + if ($LU->isInactive()) { echo "<h3>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.</h3>"; @@ -97,7 +104,7 @@ echo '</table>'; } else { // Okay, he's in. - echo '<h2 align="center">User logged in: '.$LoMa->getHandle().'</h2>'; + echo '<h2 align="center">User logged in: '.$LU->getHandle().'</h2>'; echo "<h3>Congrats, you're in</h3>"; } @@ -106,7 +113,7 @@ // Just some more debug output with no further relevance echo '<hr><pre>'; -print_r($LoMa); +print_r($LU); echo '<hr>'; print_r($_SESSION); echo '<hr>'; @@ -114,9 +121,9 @@ echo '</pre>'; echo '<br>Handle:'; -print_r($LoMa->getHandle()); +print_r($LU->getHandle()); echo '<br>User Type:'; -print_r($LoMa->getProperty('userType')); +print_r($LU->getProperty('userType')); ?> </body> </html> Index: pear/Perm_LiveUser/examples/example2/example.php diff -u pear/Perm_LiveUser/examples/example2/example.php:1.1 pear/Perm_LiveUser/examples/example2/example.php:1.2 --- pear/Perm_LiveUser/examples/example2/example.php:1.1 Sat Mar 15 09:37:28 2003 +++ pear/Perm_LiveUser/examples/example2/example.php Thu Jun 5 12:48:43 2003 @@ -11,7 +11,7 @@ * This example is intended to be used with the Auth/XML and the Perm/XML_Simple driver. * * @author Björn Kraus <krausbn@php.net> - * @version $Id: example.php,v 1.1 2003/03/15 14:37:28 krausbn Exp $ + * @version $Id: example.php,v 1.2 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -28,8 +28,11 @@ define('USETHECOMPUTER', 5); define('CONNECTINGTHEINTERNET', 6); +// Include PEAR +require_once 'PEAR.php'; + // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -40,11 +43,19 @@ echo('<hr><font color=red>'.$errObj->getMessage().':<br>'.$errObj->getUserinfo().'</font><hr>'); } -// Create new LoginManager object -$LoMa = new LoginManager('conf.xml'); -// this sets a callback function if the user hasn't logged in yet -$LoMa->setLoginFunction('testLogin'); +// Create new LiveUser (LoginManager) object. +// You need to copy the demoConf.xml and the Auth_XML.xml in the same dir +// and set in demoConf.xml the right auth container. Perm containers are +// not supported. +$LU = LiveUser::create('conf.xml'); + +// This sets a callback function if the user hasn't logged in yet +$LU->setLoginFunction('testLogin'); + +// This sets a callback function when the user tries to logout. +// In our case it's ok to use the same function. +$LU->setLogoutFunction('testLogin'); /** * Example callback function on logging in @@ -56,7 +67,7 @@ } // end func testLogin // Trigger the login process -$LoMa->init(); +$LU->init(); ?> <html> <head> @@ -67,10 +78,10 @@ <body bgcolor="#FFFFFF"> <?php // Check if the user has logged in successfully -if (!$LoMa->isLoggedIn()) { +if (!$LU->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()) { + if ($LU->isInactive()) { echo "<h3>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.</h3>"; @@ -100,7 +111,7 @@ echo '</table>'; } else { // Okay, he's in. Let's display a cross table with his rights. - echo '<h2 align="center">User logged in: '.$LoMa->getHandle().'</h2>'; + echo '<h2 align="center">User logged in: '.$LU->getHandle().'</h2>'; echo "<p>You can see user's rights in the table.</p>"; echo '<table border="1" align="center">'; @@ -112,13 +123,14 @@ echo ' </tr>'; - // kitchen - $LoMa->setCurrentArea(1); + /** + * Let's check the rights in the kitchen. + */ echo ' <tr align="center">'; echo ' <th>cooking</th>'; // check whether the user has the required right - if ($LoMa->checkRight(COOKING)) { + if ($LU->checkRight(COOKING)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -129,7 +141,7 @@ echo ' <tr align="center">'; echo ' <th>wash the dishes</th>'; // check whether the user has the required right - if ($LoMa->checkRight(WASHTHEDISHES)) { + if ($LU->checkRight(WASHTHEDISHES)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -139,14 +151,15 @@ echo ' </tr>'; - // livingroom - $LoMa->setCurrentArea(2); + /** + * Let's check the rights in the livingroom. + */ echo ' <tr align="center">'; echo ' <th>watch TV</th>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(WATCHTV)) { + if ($LU->checkRight(WATCHTV)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -157,7 +170,7 @@ echo ' <th>watch latenight TV</th>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(WATCHLATENIGHTTV)) { + if ($LU->checkRight(WATCHLATENIGHTTV)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -166,15 +179,16 @@ echo ' </tr>'; - // office - $LoMa->setCurrentArea(3); + /** + * Let's check the rights in the office. + */ echo ' <tr align="center">'; echo ' <th>use the computer</th>'; echo ' <td> </td>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(USETHECOMPUTER)) { + if ($LU->checkRight(USETHECOMPUTER)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -185,7 +199,7 @@ echo ' <td> </td>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(CONNECTINGTHEINTERNET)) { + if ($LU->checkRight(CONNECTINGTHEINTERNET)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -200,7 +214,7 @@ // Just some more debug output with no further relevance echo '<hr><pre>'; -print_r($LoMa); +print_r($LU); echo '<hr>'; print_r($_SESSION); echo '<hr>'; @@ -208,9 +222,9 @@ echo '</pre>'; echo '<br>Handle:'; -print_r($LoMa->getHandle()); +print_r($LU->getHandle()); echo '<br>User Type:'; -print_r($LoMa->getProperty('userType')); +print_r($LU->getProperty('userType')); ?> </body> </html> Index: pear/Perm_LiveUser/examples/example3/area51.php diff -u pear/Perm_LiveUser/examples/example3/area51.php:1.4 pear/Perm_LiveUser/examples/example3/area51.php:1.5 --- pear/Perm_LiveUser/examples/example3/area51.php:1.4 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/area51.php Thu Jun 5 12:48:43 2003 @@ -10,7 +10,7 @@ * * This example is intended to be used with the DB_Medium Perm driver. * - * @version $Id: area51.php,v 1.4 2003/03/24 18:03:31 krausbn Exp $ + * @version $Id: area51.php,v 1.5 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -19,9 +19,12 @@ define('LAUNCH_ATOMIC_BOMB', 4); define('FLY_ALIEN_SPACE_CRAFT', 5); +// Include configuration. require_once 'conf.php'; +// Include PEAR +require_once 'PEAR.php'; // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -42,7 +45,7 @@ } // end func testLogin // Create new LoginManager object -$LoMa = new LoginManager(getenv('DOCUMENT_ROOT').'/conf.php'); +$LU = LiveUser::create(getenv('DOCUMENT_ROOT').'/conf.php'); ?> <html> <head> @@ -54,15 +57,15 @@ <h1>Area51</h1> <p> </p> <?php -if (!$LoMa->checkRight(ACCESS)) { +if (!$LU->checkRight(ACCESS)) { echo '<p>Hey, this is a top secret area. Access denied.</p>'; } else { - echo '<p>Live long and prosper, <b>'.$LoMa->getHandle().'</b>.</p>'; - echo '<p>You have access at level <b>'.$LoMa->checkRight(ACCESS).'</b></p>'; + echo '<p>Live long and prosper, <b>'.$LU->getHandle().'</b>.</p>'; + echo '<p>You have access at level <b>'.$LU->checkRight(ACCESS).'</b></p>'; echo "<p>Please wait ... checking some rights ...<br>"; // you can even check multiple rights with one checkright call - if ($LoMa->checkRight(array(LAUNCH_ATOMIC_BOMB, FLY_ALIEN_SPACE_CRAFT))) { + if ($LU->checkRight(array(LAUNCH_ATOMIC_BOMB, FLY_ALIEN_SPACE_CRAFT))) { echo "OK, you're the boss. Let's take our alien space craft, launch the orbital atomic bombs and kick some ass! ;-)<br>"; echo "(Ehm, that was just to test our right system ...)"; } else { Index: pear/Perm_LiveUser/examples/example3/coffeemaker.php diff -u pear/Perm_LiveUser/examples/example3/coffeemaker.php:1.3 pear/Perm_LiveUser/examples/example3/coffeemaker.php:1.4 --- pear/Perm_LiveUser/examples/example3/coffeemaker.php:1.3 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/coffeemaker.php Thu Jun 5 12:48:43 2003 @@ -10,7 +10,7 @@ * * This example is intended to be used with the DB_Medium Perm driver. * - * @version $Id: coffeemaker.php,v 1.3 2003/03/24 18:03:31 krausbn Exp $ + * @version $Id: coffeemaker.php,v 1.4 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -18,9 +18,12 @@ define('MAKE_COFFEE', 6); define('DRINK_COFFEE', 7); +// Include configuration. require_once 'conf.php'; +// Include PEAR +require_once 'PEAR.php'; // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -41,7 +44,7 @@ } // end func testLogin // Create new LoginManager object -$LoMa = new LoginManager(getenv('DOCUMENT_ROOT').'/conf.php'); +$LU = LiveUser::create(getenv('DOCUMENT_ROOT').'/conf.php'); ?> <html> <head> @@ -53,32 +56,27 @@ <h1>Welcome in the Coffeemaker section!</h1> <p> </p> <?php -if (!$LoMa->checkRight(MAKE_COFFEE) && !$LoMa->checkRight(DRINK_COFFEE)) { +if (!$LU->checkRight(MAKE_COFFEE) && !$LU->checkRight(DRINK_COFFEE)) { echo "<p>Sorry, but you don't have any rights in this section</p>"; } 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 and we won't to + // AuthArea of our application is the Coffeemaker section and we want to // know whether to user is allowed to make some coffee // (the area is not needed until we won't know whether our user is an area // admin). - if ($LoMa->checkRight(MAKE_COFFEE)) { + if ($LU->checkRight(MAKE_COFFEE)) { echo "<p>Congrats, you're in the Coffeemaker section and have "; echo 'the right to make coffee!</p>'; } else { echo "<p>Your coffee tastes so bad, I won't allow you to make some</p>"; } - // You can choose: either you set the area id as second parameter in - // the checkRight function each time you call it or you set is ones for - // all further calls. - $LoMa->setCurrentArea(3); - // check if the user is allowed to drink coffee. checkRight will return the level. - if ($LoMa->checkRight(DRINK_COFFEE) == 1) { + if ($LU->checkRight(DRINK_COFFEE) == 1) { echo '<p>Yey ! You can even drink some coffee (but perhaps you should ask your boss first ;-) ))</p>'; - } elseif ($LoMa->checkRight(DRINK_COFFEE) == 3) { - echo '<p>Hi '.$LoMa->getHandle().'! Taste this delicious coffee.</p>'; + } elseif ($LU->checkRight(DRINK_COFFEE) == 3) { + echo '<p>Hi '.$LU->getHandle().'! Taste this delicious coffee.</p>'; } else { echo '<p>Well, sorry dude, you cannot drink in here</p>'; } Index: pear/Perm_LiveUser/examples/example3/conf.php diff -u pear/Perm_LiveUser/examples/example3/conf.php:1.5 pear/Perm_LiveUser/examples/example3/conf.php:1.6 --- pear/Perm_LiveUser/examples/example3/conf.php:1.5 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/conf.php Thu Jun 5 12:48:43 2003 @@ -1,5 +1,5 @@ <?php -// $Id: conf.php,v 1.5 2003/03/24 18:03:31 krausbn Exp $ +// $Id: conf.php,v 1.6 2003/06/05 16:48:43 krausbn Exp $ // set pear include path here $tmp = explode('/', getenv('DOCUMENT_ROOT')); $tmp[(count($tmp)-1)] = 'pear'; @@ -21,6 +21,7 @@ 'forceLogin' => true, 'autoInit' => true, 'loginFunction' => 'testLogin', + 'logoutFunction' => 'testLogin', 'authContainers' => array(0 => array('type' => 'DB', 'dsn' => 'mysql://root:root@localhost/test', 'loginTimeout' => 0, Index: pear/Perm_LiveUser/examples/example3/testarea.php diff -u pear/Perm_LiveUser/examples/example3/testarea.php:1.4 pear/Perm_LiveUser/examples/example3/testarea.php:1.5 --- pear/Perm_LiveUser/examples/example3/testarea.php:1.4 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/testarea.php Thu Jun 5 12:48:43 2003 @@ -10,7 +10,7 @@ * * This example is intended to be used with the DB_Medium Perm driver. * - * @version $Id: testarea.php,v 1.4 2003/03/24 18:03:31 krausbn Exp $ + * @version $Id: testarea.php,v 1.5 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -18,9 +18,12 @@ define('READ_TESTS', 1); define('WRITE_TESTS', 2); +// Include configuration. require_once 'conf.php'; +// Include PEAR +require_once 'PEAR.php'; // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -36,12 +39,12 @@ */ function testLogin() { - header('Location: loginscreen.php?target=testarea.php'); + header('Location: loginscreen.php?target=coffeemaker.php'); exit(); } // end func testLogin // Create new LoginManager object -$LoMa = new LoginManager(getenv('DOCUMENT_ROOT').'/conf.php'); +$LU = LiveUser::create(getenv('DOCUMENT_ROOT').'/conf.php'); ?> <html> <head> @@ -53,13 +56,13 @@ <h1>Testarea</h1> <p> </p> <?php -if (!$LoMa->checkRight(READ_TESTS) && !$LoMa->checkRight(WRITE_TESTS)) { +if (!$LU->checkRight(READ_TESTS) && !$LU->checkRight(WRITE_TESTS)) { echo "<p>Sorry, but you don't have any rights in this section</p>"; } else { - if ($LoMa->checkRight(READ_TESTS)) { + if ($LU->checkRight(READ_TESTS)) { echo "<p>Wow, you've the right to <b>read</b> the latest posting in this list!<br>"; echo "OK, let's search the database for the last entry ...</p>"; - echo "<p>User: <b>".$LoMa->getProperty('handle')."</b><br>LastLogin: <b>".strftime('%Y-%m-%d %H:%M', $LoMa->getProperty('lastLogin'))."</b><br>"; + echo "<p>User: <b>".$LU->getProperty('handle')."</b><br>LastLogin: <b>".strftime('%Y-%m-%d %H:%M', $LU->getProperty('lastLogin'))."</b><br>"; echo "<pre>Hi!<br>I'm just testing whether this really cool LiveUser program works :-)<br>"; echo "Hmm, think it runs perfect!</pre>"; } @@ -69,7 +72,7 @@ <p> <textarea name="textfield" cols="80" rows="10"<?php // let's see if the user is allowed to post something - if ($LoMa->checkRight(WRITE_TESTS)) { + if ($LU->checkRight(WRITE_TESTS)) { echo '>'; # end the textarea tag echo 'Type something.'; } else { Index: pear/Perm_LiveUser/examples/example4/demodata.sql diff -u pear/Perm_LiveUser/examples/example4/demodata.sql:1.1 pear/Perm_LiveUser/examples/example4/demodata.sql:1.2 --- pear/Perm_LiveUser/examples/example4/demodata.sql:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/demodata.sql Thu Jun 5 12:48:43 2003 @@ -206,6 +206,7 @@ INSERT INTO liveuser_groupusers VALUES (1, 1); INSERT INTO liveuser_groupusers VALUES (2, 2); +INSERT INTO liveuser_groupusers VALUES (2, 3); INSERT INTO liveuser_groupusers VALUES (3, 2); INSERT INTO liveuser_groupusers VALUES (4, 3); # -------------------------------------------------------- @@ -421,4 +422,4 @@ INSERT INTO news VALUES (1, '2003-03-16 22:17:21', '2003-03-30 23:17:21', 'Just testing my rights.', 3, 2); INSERT INTO news VALUES (2, '2003-03-16 21:53:41', '2003-04-13 22:53:41', 'Another test ;-)', 1, 1); INSERT INTO news VALUES (3, '2003-03-16 22:42:27', '2003-04-06 23:42:27', 'Yeah! I can make some test postings here', 2, 2); -INSERT INTO news VALUES (4, '2003-03-16 23:00:29', '2003-03-23 23:00:29', 'LiveUser is really a cool tool :-)', 4, 3); +INSERT INTO news VALUES (4, '2003-03-16 23:00:29', '2003-03-23 23:00:29', 'LiveUser is really a cool tool :-)', 4, 3); \ No newline at end of file Index: pear/Perm_LiveUser/examples/example4/finish.inc.php diff -u pear/Perm_LiveUser/examples/example4/finish.inc.php:1.1 pear/Perm_LiveUser/examples/example4/finish.inc.php:1.2 --- pear/Perm_LiveUser/examples/example4/finish.inc.php:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/finish.inc.php Thu Jun 5 12:48:43 2003 @@ -2,13 +2,13 @@ // we could also make a db query, but I'm too lazy at this point ;-) $groups = array('', 'Admins', 'GroupA', 'GroupB'); - foreach ($LoMa->getProperty('groupIds') as $id) { + foreach ($LU->getProperty('groupIds') as $id) { $userGroups[] = $groups[$id]; } - $tpl->setVariable(array('user' => $LoMa->getHandle(), + $tpl->setVariable(array('user' => $LU->getHandle(), 'group' => implode(', ', $userGroups), - 'lastLogin' => date('d.m.Y H:i', $LoMa->getProperty('lastLogin')))); + 'lastLogin' => date('d.m.Y H:i', $LU->getProperty('lastLogin')))); $tpl->show(); ?> Index: pear/Perm_LiveUser/examples/example4/main.inc.php diff -u pear/Perm_LiveUser/examples/example4/main.inc.php:1.4 pear/Perm_LiveUser/examples/example4/main.inc.php:1.5 --- pear/Perm_LiveUser/examples/example4/main.inc.php:1.4 Mon Mar 24 13:03:32 2003 +++ pear/Perm_LiveUser/examples/example4/main.inc.php Thu Jun 5 12:48:43 2003 @@ -74,7 +74,12 @@ 'type' => 'mysql', 'name' => 'test', 'user' => 'root', - 'pwd' => 'root') + 'pwd' => 'root'), +'www.local-liveuser.de' => array('host' => 'localhost', + 'type' => 'mysql', + 'name' => 'test3', + 'user' => 'root', + 'pwd' => 'root'), ); @@ -92,21 +97,21 @@ $tpl = new HTML_Template_IT(); - require_once 'LiveUser/LoginManager.php'; - $LoMa = new LoginManager(); + require_once 'LiveUser/LiveUser.php'; + $LU = new LiveUser(); - $LoMa->allowCookies = true; - $LoMa->cookieDomain = HTTP_HOST; - $LoMa->forceLogin = true; - $LoMa->loginFunction = 'showLoginForm'; - $LoMa->authContainers[0] = array('type' => 'DB', + $LU->allowCookies = true; + $LU->cookieDomain = HTTP_HOST; + $LU->forceLogin = true; + $LU->loginFunction = 'showLoginForm'; + $LU->authContainers[0] = array('type' => 'DB', 'connection' => $db, 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'allowDuplicateHandles' => 0, 'prefix' => 'liveuser_'); - $LoMa->permContainer = array('type' => 'DB_Complex', + $LU->permContainer = array('type' => 'DB_Complex', 'connection' => $db, 'prefix' => 'liveuser_'); @@ -115,5 +120,5 @@ define('RIGHT_NEWS_CHANGE', 2); define('RIGHT_NEWS_DELETE', 3); - $LoMa->init(); + $LU->init(); ?> Index: pear/Perm_LiveUser/examples/example4/news_change.php diff -u pear/Perm_LiveUser/examples/example4/news_change.php:1.1 pear/Perm_LiveUser/examples/example4/news_change.php:1.2 --- pear/Perm_LiveUser/examples/example4/news_change.php:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/news_change.php Thu Jun 5 12:48:43 2003 @@ -3,7 +3,7 @@ require_once getEnv('DOCUMENT_ROOT') . '/main.inc.php'; // If the user hasn't the right to change news -> access denied. - if (!$LoMa->checkRight(RIGHT_NEWS_CHANGE, AREA_NEWS)) { + if (!$LU->checkRight(RIGHT_NEWS_CHANGE)) { $tpl->loadTemplatefile('news_notallowed.tpl.php'); include_once WEB_ROOT . '/finish.inc.php'; exit(); @@ -34,7 +34,7 @@ news_id = '.$news_id); // Check whether the user is cheating. - if (!$LoMa->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$newsRow['owner_user_id'], (int)$newsRow['owner_group_id'], AREA_NEWS)) { + if (!$LU->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$newsRow['owner_user_id'], (int)$newsRow['owner_group_id'])) { header('Location: http://'.HTTP_HOST.'/news_change.php?logout=1'); exit(); } else { @@ -114,7 +114,7 @@ news_id = '.$news_id); // Check whether the user is cheating. - if(!$LoMa->checkRightLevel(RIGHT_NEWS_DELETE, (int)$rightInfo['owner_user_id'], (int)$rightInfo['owner_group_id'], AREA_NEWS)) { + if(!$LU->checkRightLevel(RIGHT_NEWS_DELETE, (int)$rightInfo['owner_user_id'], (int)$rightInfo['owner_group_id'])) { header('Location: http://'.HTTP_HOST.'/news_change.php?logout=1'); } else { $confirmed = isset($_GET['is_js_confirmed']) ? $_GET['is_js_confirmed'] : 0; @@ -172,12 +172,12 @@ 'author' => '<a href="mailto:'.$row['handle'].'@your-company.com">'.$row['handle'].'</a>')); // Has the user the right to change the news? - if ($LoMa->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$row['owner_user_id'], (int)$row['owner_group_id'], AREA_NEWS)) { + if ($LU->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$row['owner_user_id'], (int)$row['owner_group_id'])) { $tpl->setVariable('link_change', 'news_change.php?action=change&news_id='.$row['news_id']); } // Has the user the right to delete the news? - if ($LoMa->checkRightLevel(RIGHT_NEWS_DELETE, (int)$row['owner_user_id'], (int)$row['owner_group_id'], AREA_NEWS)) { + if ($LU->checkRightLevel(RIGHT_NEWS_DELETE, (int)$row['owner_user_id'], (int)$row['owner_group_id'])) { $tpl->setVariable('link_delete', 'news_change.php?action=delete&news_id='.$row['news_id'].'" onclick="return confirmLink(this, \'Shall I really delete \\\''.htmlentities(substr(str_replace('<br>', ' ', $row['news']), 0, 20), ENT_QUOTES).' ...\\\' ?\')'); } Index: pear/Perm_LiveUser/examples/example4/news_new.php diff -u pear/Perm_LiveUser/examples/example4/news_new.php:1.1 pear/Perm_LiveUser/examples/example4/news_new.php:1.2 --- pear/Perm_LiveUser/examples/example4/news_new.php:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/news_new.php Thu Jun 5 12:48:43 2003 @@ -3,7 +3,7 @@ require_once getEnv('DOCUMENT_ROOT') . '/main.inc.php'; // If the user hasn't the right to write news -> access denied. - if (!$LoMa->checkRight(RIGHT_NEWS_NEW, AREA_NEWS)) { + if (!$LU->checkRight(RIGHT_NEWS_NEW)) { $tpl->loadTemplatefile('news_notallowed.tpl.php'); include_once WEB_ROOT . '/finish.inc.php'; exit(); @@ -24,7 +24,7 @@ $tpl->setVariable('script_msg', '<p><font color="red">Only numbers between 1 and 99 are allowed here.</font></p>'); } - elseif (!$LoMa->checkRightLevel(RIGHT_NEWS_NEW, $LoMa->getProperty('permUserId'), $group, AREA_NEWS)) { + elseif (!$LU->checkRightLevel(RIGHT_NEWS_NEW, $LU->getProperty('permUserId'), $group)) { $tpl->setVariable('script_msg', '<p><font color="red">You don\'t have the right to post news for this group.</font></p>'); } @@ -44,7 +44,7 @@ NOW(), '.$db->quote(date('Y.m.d H:i:s', time()+60*60*24*7*$valid_to)).', '.$db->quote(addslashes($news)).', - '.$db->quote($LoMa->getProperty('permUserId')).', + '.$db->quote($LU->getProperty('permUserId')).', '.$group.')'); $tpl->setVariable('script_msg', '<p><b>News has been added.</b></p>'); @@ -69,14 +69,14 @@ } // If the user is member in more than one group, show them. - if (count($LoMa->getProperty('groupIds')) > 1) { + if (count($LU->getProperty('groupIds')) > 1) { $res = $db->query('SELECT group_id, group_comment FROM liveuser_group_names WHERE - group_id IN ('.implode(', ', $LoMa->getProperty('groupIds')).') + group_id IN ('.implode(', ', $LU->getProperty('groupIds')).') ORDER BY group_id'); @@ -92,7 +92,7 @@ } else { $tpl->setCurrentBlock('set_group'); - $tpl->setVariable('group_id', current($LoMa->getProperty('groupIds'))); + $tpl->setVariable('group_id', current($LU->getProperty('groupIds'))); $tpl->parseCurrentBlock(); }
Index: pear/Perm_LiveUser/examples/example1/example.php diff -u pear/Perm_LiveUser/examples/example1/example.php:1.1 pear/Perm_LiveUser/examples/example1/example.php:1.2 --- pear/Perm_LiveUser/examples/example1/example.php:1.1 Sat Mar 15 09:37:46 2003 +++ pear/Perm_LiveUser/examples/example1/example.php Thu Jun 5 12:48:43 2003 @@ -12,7 +12,7 @@ * No permission management is supported. * * @author Björn Kraus <krausbn@php.net> - * @version $Id: example.php,v 1.1 2003/03/15 14:37:46 krausbn Exp $ + * @version $Id: example.php,v 1.2 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -21,8 +21,11 @@ $tmp[(count($tmp)-1)] = 'pear'; ini_set('include_path', implode('/', $tmp)); +// Include PEAR +require_once 'PEAR.php'; + // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -38,10 +41,14 @@ // You need to copy the demoConf.xml and the Auth_XML.xml in the same dir // and set in demoConf.xml the right auth container. Perm containers are // not supported. -$LoMa = new LoginManager('conf.xml'); +$LU = LiveUser::create('conf.xml'); + +// This sets a callback function if the user hasn't logged in yet +$LU->setLoginFunction('testLogin'); -// this sets a callback function if the user hasn't logged in yet -$LoMa->setLoginFunction('testLogin'); +// This sets a callback function when the user tries to logout. +// In our case it's ok to use the same function. +$LU->setLogoutFunction('testLogin'); /** * Example callback function on logging in @@ -53,7 +60,7 @@ } // end func testLogin // Trigger the login process -$LoMa->init(); +$LU->init(); ?> <html> <head> @@ -64,10 +71,10 @@ <body bgcolor="#FFFFFF"> <?php // Check if the user has logged in successfully -if (!$LoMa->isLoggedIn()) { +if (!$LU->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()) { + if ($LU->isInactive()) { echo "<h3>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.</h3>"; @@ -97,7 +104,7 @@ echo '</table>'; } else { // Okay, he's in. - echo '<h2 align="center">User logged in: '.$LoMa->getHandle().'</h2>'; + echo '<h2 align="center">User logged in: '.$LU->getHandle().'</h2>'; echo "<h3>Congrats, you're in</h3>"; } @@ -106,7 +113,7 @@ // Just some more debug output with no further relevance echo '<hr><pre>'; -print_r($LoMa); +print_r($LU); echo '<hr>'; print_r($_SESSION); echo '<hr>'; @@ -114,9 +121,9 @@ echo '</pre>'; echo '<br>Handle:'; -print_r($LoMa->getHandle()); +print_r($LU->getHandle()); echo '<br>User Type:'; -print_r($LoMa->getProperty('userType')); +print_r($LU->getProperty('userType')); ?> </body> </html> Index: pear/Perm_LiveUser/examples/example2/example.php diff -u pear/Perm_LiveUser/examples/example2/example.php:1.1 pear/Perm_LiveUser/examples/example2/example.php:1.2 --- pear/Perm_LiveUser/examples/example2/example.php:1.1 Sat Mar 15 09:37:28 2003 +++ pear/Perm_LiveUser/examples/example2/example.php Thu Jun 5 12:48:43 2003 @@ -11,7 +11,7 @@ * This example is intended to be used with the Auth/XML and the Perm/XML_Simple driver. * * @author Björn Kraus <krausbn@php.net> - * @version $Id: example.php,v 1.1 2003/03/15 14:37:28 krausbn Exp $ + * @version $Id: example.php,v 1.2 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -28,8 +28,11 @@ define('USETHECOMPUTER', 5); define('CONNECTINGTHEINTERNET', 6); +// Include PEAR +require_once 'PEAR.php'; + // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -40,11 +43,19 @@ echo('<hr><font color=red>'.$errObj->getMessage().':<br>'.$errObj->getUserinfo().'</font><hr>'); } -// Create new LoginManager object -$LoMa = new LoginManager('conf.xml'); -// this sets a callback function if the user hasn't logged in yet -$LoMa->setLoginFunction('testLogin'); +// Create new LiveUser (LoginManager) object. +// You need to copy the demoConf.xml and the Auth_XML.xml in the same dir +// and set in demoConf.xml the right auth container. Perm containers are +// not supported. +$LU = LiveUser::create('conf.xml'); + +// This sets a callback function if the user hasn't logged in yet +$LU->setLoginFunction('testLogin'); + +// This sets a callback function when the user tries to logout. +// In our case it's ok to use the same function. +$LU->setLogoutFunction('testLogin'); /** * Example callback function on logging in @@ -56,7 +67,7 @@ } // end func testLogin // Trigger the login process -$LoMa->init(); +$LU->init(); ?> <html> <head> @@ -67,10 +78,10 @@ <body bgcolor="#FFFFFF"> <?php // Check if the user has logged in successfully -if (!$LoMa->isLoggedIn()) { +if (!$LU->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()) { + if ($LU->isInactive()) { echo "<h3>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.</h3>"; @@ -100,7 +111,7 @@ echo '</table>'; } else { // Okay, he's in. Let's display a cross table with his rights. - echo '<h2 align="center">User logged in: '.$LoMa->getHandle().'</h2>'; + echo '<h2 align="center">User logged in: '.$LU->getHandle().'</h2>'; echo "<p>You can see user's rights in the table.</p>"; echo '<table border="1" align="center">'; @@ -112,13 +123,14 @@ echo ' </tr>'; - // kitchen - $LoMa->setCurrentArea(1); + /** + * Let's check the rights in the kitchen. + */ echo ' <tr align="center">'; echo ' <th>cooking</th>'; // check whether the user has the required right - if ($LoMa->checkRight(COOKING)) { + if ($LU->checkRight(COOKING)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -129,7 +141,7 @@ echo ' <tr align="center">'; echo ' <th>wash the dishes</th>'; // check whether the user has the required right - if ($LoMa->checkRight(WASHTHEDISHES)) { + if ($LU->checkRight(WASHTHEDISHES)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -139,14 +151,15 @@ echo ' </tr>'; - // livingroom - $LoMa->setCurrentArea(2); + /** + * Let's check the rights in the livingroom. + */ echo ' <tr align="center">'; echo ' <th>watch TV</th>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(WATCHTV)) { + if ($LU->checkRight(WATCHTV)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -157,7 +170,7 @@ echo ' <th>watch latenight TV</th>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(WATCHLATENIGHTTV)) { + if ($LU->checkRight(WATCHLATENIGHTTV)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -166,15 +179,16 @@ echo ' </tr>'; - // office - $LoMa->setCurrentArea(3); + /** + * Let's check the rights in the office. + */ echo ' <tr align="center">'; echo ' <th>use the computer</th>'; echo ' <td> </td>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(USETHECOMPUTER)) { + if ($LU->checkRight(USETHECOMPUTER)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -185,7 +199,7 @@ echo ' <td> </td>'; echo ' <td> </td>'; // check whether the user has the required right - if ($LoMa->checkRight(CONNECTINGTHEINTERNET)) { + if ($LU->checkRight(CONNECTINGTHEINTERNET)) { echo ' <td><b>X</b></td>'; } else { echo ' <td> </td>'; @@ -200,7 +214,7 @@ // Just some more debug output with no further relevance echo '<hr><pre>'; -print_r($LoMa); +print_r($LU); echo '<hr>'; print_r($_SESSION); echo '<hr>'; @@ -208,9 +222,9 @@ echo '</pre>'; echo '<br>Handle:'; -print_r($LoMa->getHandle()); +print_r($LU->getHandle()); echo '<br>User Type:'; -print_r($LoMa->getProperty('userType')); +print_r($LU->getProperty('userType')); ?> </body> </html> Index: pear/Perm_LiveUser/examples/example3/area51.php diff -u pear/Perm_LiveUser/examples/example3/area51.php:1.4 pear/Perm_LiveUser/examples/example3/area51.php:1.5 --- pear/Perm_LiveUser/examples/example3/area51.php:1.4 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/area51.php Thu Jun 5 12:48:43 2003 @@ -10,7 +10,7 @@ * * This example is intended to be used with the DB_Medium Perm driver. * - * @version $Id: area51.php,v 1.4 2003/03/24 18:03:31 krausbn Exp $ + * @version $Id: area51.php,v 1.5 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -19,9 +19,12 @@ define('LAUNCH_ATOMIC_BOMB', 4); define('FLY_ALIEN_SPACE_CRAFT', 5); +// Include configuration. require_once 'conf.php'; +// Include PEAR +require_once 'PEAR.php'; // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -42,7 +45,7 @@ } // end func testLogin // Create new LoginManager object -$LoMa = new LoginManager(getenv('DOCUMENT_ROOT').'/conf.php'); +$LU = LiveUser::create(getenv('DOCUMENT_ROOT').'/conf.php'); ?> <html> <head> @@ -54,15 +57,15 @@ <h1>Area51</h1> <p> </p> <?php -if (!$LoMa->checkRight(ACCESS)) { +if (!$LU->checkRight(ACCESS)) { echo '<p>Hey, this is a top secret area. Access denied.</p>'; } else { - echo '<p>Live long and prosper, <b>'.$LoMa->getHandle().'</b>.</p>'; - echo '<p>You have access at level <b>'.$LoMa->checkRight(ACCESS).'</b></p>'; + echo '<p>Live long and prosper, <b>'.$LU->getHandle().'</b>.</p>'; + echo '<p>You have access at level <b>'.$LU->checkRight(ACCESS).'</b></p>'; echo "<p>Please wait ... checking some rights ...<br>"; // you can even check multiple rights with one checkright call - if ($LoMa->checkRight(array(LAUNCH_ATOMIC_BOMB, FLY_ALIEN_SPACE_CRAFT))) { + if ($LU->checkRight(array(LAUNCH_ATOMIC_BOMB, FLY_ALIEN_SPACE_CRAFT))) { echo "OK, you're the boss. Let's take our alien space craft, launch the orbital atomic bombs and kick some ass! ;-)<br>"; echo "(Ehm, that was just to test our right system ...)"; } else { Index: pear/Perm_LiveUser/examples/example3/coffeemaker.php diff -u pear/Perm_LiveUser/examples/example3/coffeemaker.php:1.3 pear/Perm_LiveUser/examples/example3/coffeemaker.php:1.4 --- pear/Perm_LiveUser/examples/example3/coffeemaker.php:1.3 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/coffeemaker.php Thu Jun 5 12:48:43 2003 @@ -10,7 +10,7 @@ * * This example is intended to be used with the DB_Medium Perm driver. * - * @version $Id: coffeemaker.php,v 1.3 2003/03/24 18:03:31 krausbn Exp $ + * @version $Id: coffeemaker.php,v 1.4 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -18,9 +18,12 @@ define('MAKE_COFFEE', 6); define('DRINK_COFFEE', 7); +// Include configuration. require_once 'conf.php'; +// Include PEAR +require_once 'PEAR.php'; // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -41,7 +44,7 @@ } // end func testLogin // Create new LoginManager object -$LoMa = new LoginManager(getenv('DOCUMENT_ROOT').'/conf.php'); +$LU = LiveUser::create(getenv('DOCUMENT_ROOT').'/conf.php'); ?> <html> <head> @@ -53,32 +56,27 @@ <h1>Welcome in the Coffeemaker section!</h1> <p> </p> <?php -if (!$LoMa->checkRight(MAKE_COFFEE) && !$LoMa->checkRight(DRINK_COFFEE)) { +if (!$LU->checkRight(MAKE_COFFEE) && !$LU->checkRight(DRINK_COFFEE)) { echo "<p>Sorry, but you don't have any rights in this section</p>"; } 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 and we won't to + // AuthArea of our application is the Coffeemaker section and we want to // know whether to user is allowed to make some coffee // (the area is not needed until we won't know whether our user is an area // admin). - if ($LoMa->checkRight(MAKE_COFFEE)) { + if ($LU->checkRight(MAKE_COFFEE)) { echo "<p>Congrats, you're in the Coffeemaker section and have "; echo 'the right to make coffee!</p>'; } else { echo "<p>Your coffee tastes so bad, I won't allow you to make some</p>"; } - // You can choose: either you set the area id as second parameter in - // the checkRight function each time you call it or you set is ones for - // all further calls. - $LoMa->setCurrentArea(3); - // check if the user is allowed to drink coffee. checkRight will return the level. - if ($LoMa->checkRight(DRINK_COFFEE) == 1) { + if ($LU->checkRight(DRINK_COFFEE) == 1) { echo '<p>Yey ! You can even drink some coffee (but perhaps you should ask your boss first ;-) ))</p>'; - } elseif ($LoMa->checkRight(DRINK_COFFEE) == 3) { - echo '<p>Hi '.$LoMa->getHandle().'! Taste this delicious coffee.</p>'; + } elseif ($LU->checkRight(DRINK_COFFEE) == 3) { + echo '<p>Hi '.$LU->getHandle().'! Taste this delicious coffee.</p>'; } else { echo '<p>Well, sorry dude, you cannot drink in here</p>'; } Index: pear/Perm_LiveUser/examples/example3/conf.php diff -u pear/Perm_LiveUser/examples/example3/conf.php:1.5 pear/Perm_LiveUser/examples/example3/conf.php:1.6 --- pear/Perm_LiveUser/examples/example3/conf.php:1.5 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/conf.php Thu Jun 5 12:48:43 2003 @@ -1,5 +1,5 @@ <?php -// $Id: conf.php,v 1.5 2003/03/24 18:03:31 krausbn Exp $ +// $Id: conf.php,v 1.6 2003/06/05 16:48:43 krausbn Exp $ // set pear include path here $tmp = explode('/', getenv('DOCUMENT_ROOT')); $tmp[(count($tmp)-1)] = 'pear'; @@ -21,6 +21,7 @@ 'forceLogin' => true, 'autoInit' => true, 'loginFunction' => 'testLogin', + 'logoutFunction' => 'testLogin', 'authContainers' => array(0 => array('type' => 'DB', 'dsn' => 'mysql://root:root@localhost/test', 'loginTimeout' => 0, Index: pear/Perm_LiveUser/examples/example3/testarea.php diff -u pear/Perm_LiveUser/examples/example3/testarea.php:1.4 pear/Perm_LiveUser/examples/example3/testarea.php:1.5 --- pear/Perm_LiveUser/examples/example3/testarea.php:1.4 Mon Mar 24 13:03:31 2003 +++ pear/Perm_LiveUser/examples/example3/testarea.php Thu Jun 5 12:48:43 2003 @@ -10,7 +10,7 @@ * * This example is intended to be used with the DB_Medium Perm driver. * - * @version $Id: testarea.php,v 1.4 2003/03/24 18:03:31 krausbn Exp $ + * @version $Id: testarea.php,v 1.5 2003/06/05 16:48:43 krausbn Exp $ **/ error_reporting(E_ALL); @@ -18,9 +18,12 @@ define('READ_TESTS', 1); define('WRITE_TESTS', 2); +// Include configuration. require_once 'conf.php'; +// Include PEAR +require_once 'PEAR.php'; // Get LoginManager class definition -require_once 'LiveUser/LoginManager.php'; +require_once 'LiveUser/LiveUser.php'; // The error handling stuff is not needed and used only for debugging // while LiveUser is not yet mature @@ -36,12 +39,12 @@ */ function testLogin() { - header('Location: loginscreen.php?target=testarea.php'); + header('Location: loginscreen.php?target=coffeemaker.php'); exit(); } // end func testLogin // Create new LoginManager object -$LoMa = new LoginManager(getenv('DOCUMENT_ROOT').'/conf.php'); +$LU = LiveUser::create(getenv('DOCUMENT_ROOT').'/conf.php'); ?> <html> <head> @@ -53,13 +56,13 @@ <h1>Testarea</h1> <p> </p> <?php -if (!$LoMa->checkRight(READ_TESTS) && !$LoMa->checkRight(WRITE_TESTS)) { +if (!$LU->checkRight(READ_TESTS) && !$LU->checkRight(WRITE_TESTS)) { echo "<p>Sorry, but you don't have any rights in this section</p>"; } else { - if ($LoMa->checkRight(READ_TESTS)) { + if ($LU->checkRight(READ_TESTS)) { echo "<p>Wow, you've the right to <b>read</b> the latest posting in this list!<br>"; echo "OK, let's search the database for the last entry ...</p>"; - echo "<p>User: <b>".$LoMa->getProperty('handle')."</b><br>LastLogin: <b>".strftime('%Y-%m-%d %H:%M', $LoMa->getProperty('lastLogin'))."</b><br>"; + echo "<p>User: <b>".$LU->getProperty('handle')."</b><br>LastLogin: <b>".strftime('%Y-%m-%d %H:%M', $LU->getProperty('lastLogin'))."</b><br>"; echo "<pre>Hi!<br>I'm just testing whether this really cool LiveUser program works :-)<br>"; echo "Hmm, think it runs perfect!</pre>"; } @@ -69,7 +72,7 @@ <p> <textarea name="textfield" cols="80" rows="10"<?php // let's see if the user is allowed to post something - if ($LoMa->checkRight(WRITE_TESTS)) { + if ($LU->checkRight(WRITE_TESTS)) { echo '>'; # end the textarea tag echo 'Type something.'; } else { Index: pear/Perm_LiveUser/examples/example4/demodata.sql diff -u pear/Perm_LiveUser/examples/example4/demodata.sql:1.1 pear/Perm_LiveUser/examples/example4/demodata.sql:1.2 --- pear/Perm_LiveUser/examples/example4/demodata.sql:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/demodata.sql Thu Jun 5 12:48:43 2003 @@ -206,6 +206,7 @@ INSERT INTO liveuser_groupusers VALUES (1, 1); INSERT INTO liveuser_groupusers VALUES (2, 2); +INSERT INTO liveuser_groupusers VALUES (2, 3); INSERT INTO liveuser_groupusers VALUES (3, 2); INSERT INTO liveuser_groupusers VALUES (4, 3); # -------------------------------------------------------- @@ -421,4 +422,4 @@ INSERT INTO news VALUES (1, '2003-03-16 22:17:21', '2003-03-30 23:17:21', 'Just testing my rights.', 3, 2); INSERT INTO news VALUES (2, '2003-03-16 21:53:41', '2003-04-13 22:53:41', 'Another test ;-)', 1, 1); INSERT INTO news VALUES (3, '2003-03-16 22:42:27', '2003-04-06 23:42:27', 'Yeah! I can make some test postings here', 2, 2); -INSERT INTO news VALUES (4, '2003-03-16 23:00:29', '2003-03-23 23:00:29', 'LiveUser is really a cool tool :-)', 4, 3); +INSERT INTO news VALUES (4, '2003-03-16 23:00:29', '2003-03-23 23:00:29', 'LiveUser is really a cool tool :-)', 4, 3); \ No newline at end of file Index: pear/Perm_LiveUser/examples/example4/finish.inc.php diff -u pear/Perm_LiveUser/examples/example4/finish.inc.php:1.1 pear/Perm_LiveUser/examples/example4/finish.inc.php:1.2 --- pear/Perm_LiveUser/examples/example4/finish.inc.php:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/finish.inc.php Thu Jun 5 12:48:43 2003 @@ -2,13 +2,13 @@ // we could also make a db query, but I'm too lazy at this point ;-) $groups = array('', 'Admins', 'GroupA', 'GroupB'); - foreach ($LoMa->getProperty('groupIds') as $id) { + foreach ($LU->getProperty('groupIds') as $id) { $userGroups[] = $groups[$id]; } - $tpl->setVariable(array('user' => $LoMa->getHandle(), + $tpl->setVariable(array('user' => $LU->getHandle(), 'group' => implode(', ', $userGroups), - 'lastLogin' => date('d.m.Y H:i', $LoMa->getProperty('lastLogin')))); + 'lastLogin' => date('d.m.Y H:i', $LU->getProperty('lastLogin')))); $tpl->show(); ?> Index: pear/Perm_LiveUser/examples/example4/main.inc.php diff -u pear/Perm_LiveUser/examples/example4/main.inc.php:1.4 pear/Perm_LiveUser/examples/example4/main.inc.php:1.5 --- pear/Perm_LiveUser/examples/example4/main.inc.php:1.4 Mon Mar 24 13:03:32 2003 +++ pear/Perm_LiveUser/examples/example4/main.inc.php Thu Jun 5 12:48:43 2003 @@ -74,7 +74,12 @@ 'type' => 'mysql', 'name' => 'test', 'user' => 'root', - 'pwd' => 'root') + 'pwd' => 'root'), +'www.local-liveuser.de' => array('host' => 'localhost', + 'type' => 'mysql', + 'name' => 'test3', + 'user' => 'root', + 'pwd' => 'root'), ); @@ -92,21 +97,21 @@ $tpl = new HTML_Template_IT(); - require_once 'LiveUser/LoginManager.php'; - $LoMa = new LoginManager(); + require_once 'LiveUser/LiveUser.php'; + $LU = new LiveUser(); - $LoMa->allowCookies = true; - $LoMa->cookieDomain = HTTP_HOST; - $LoMa->forceLogin = true; - $LoMa->loginFunction = 'showLoginForm'; - $LoMa->authContainers[0] = array('type' => 'DB', + $LU->allowCookies = true; + $LU->cookieDomain = HTTP_HOST; + $LU->forceLogin = true; + $LU->loginFunction = 'showLoginForm'; + $LU->authContainers[0] = array('type' => 'DB', 'connection' => $db, 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'allowDuplicateHandles' => 0, 'prefix' => 'liveuser_'); - $LoMa->permContainer = array('type' => 'DB_Complex', + $LU->permContainer = array('type' => 'DB_Complex', 'connection' => $db, 'prefix' => 'liveuser_'); @@ -115,5 +120,5 @@ define('RIGHT_NEWS_CHANGE', 2); define('RIGHT_NEWS_DELETE', 3); - $LoMa->init(); + $LU->init(); ?> Index: pear/Perm_LiveUser/examples/example4/news_change.php diff -u pear/Perm_LiveUser/examples/example4/news_change.php:1.1 pear/Perm_LiveUser/examples/example4/news_change.php:1.2 --- pear/Perm_LiveUser/examples/example4/news_change.php:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/news_change.php Thu Jun 5 12:48:43 2003 @@ -3,7 +3,7 @@ require_once getEnv('DOCUMENT_ROOT') . '/main.inc.php'; // If the user hasn't the right to change news -> access denied. - if (!$LoMa->checkRight(RIGHT_NEWS_CHANGE, AREA_NEWS)) { + if (!$LU->checkRight(RIGHT_NEWS_CHANGE)) { $tpl->loadTemplatefile('news_notallowed.tpl.php'); include_once WEB_ROOT . '/finish.inc.php'; exit(); @@ -34,7 +34,7 @@ news_id = '.$news_id); // Check whether the user is cheating. - if (!$LoMa->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$newsRow['owner_user_id'], (int)$newsRow['owner_group_id'], AREA_NEWS)) { + if (!$LU->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$newsRow['owner_user_id'], (int)$newsRow['owner_group_id'])) { header('Location: http://'.HTTP_HOST.'/news_change.php?logout=1'); exit(); } else { @@ -114,7 +114,7 @@ news_id = '.$news_id); // Check whether the user is cheating. - if(!$LoMa->checkRightLevel(RIGHT_NEWS_DELETE, (int)$rightInfo['owner_user_id'], (int)$rightInfo['owner_group_id'], AREA_NEWS)) { + if(!$LU->checkRightLevel(RIGHT_NEWS_DELETE, (int)$rightInfo['owner_user_id'], (int)$rightInfo['owner_group_id'])) { header('Location: http://'.HTTP_HOST.'/news_change.php?logout=1'); } else { $confirmed = isset($_GET['is_js_confirmed']) ? $_GET['is_js_confirmed'] : 0; @@ -172,12 +172,12 @@ 'author' => '<a href="mailto:'.$row['handle'].'@your-company.com">'.$row['handle'].'</a>')); // Has the user the right to change the news? - if ($LoMa->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$row['owner_user_id'], (int)$row['owner_group_id'], AREA_NEWS)) { + if ($LU->checkRightLevel(RIGHT_NEWS_CHANGE, (int)$row['owner_user_id'], (int)$row['owner_group_id'])) { $tpl->setVariable('link_change', 'news_change.php?action=change&news_id='.$row['news_id']); } // Has the user the right to delete the news? - if ($LoMa->checkRightLevel(RIGHT_NEWS_DELETE, (int)$row['owner_user_id'], (int)$row['owner_group_id'], AREA_NEWS)) { + if ($LU->checkRightLevel(RIGHT_NEWS_DELETE, (int)$row['owner_user_id'], (int)$row['owner_group_id'])) { $tpl->setVariable('link_delete', 'news_change.php?action=delete&news_id='.$row['news_id'].'" onclick="return confirmLink(this, \'Shall I really delete \\\''.htmlentities(substr(str_replace('<br>', ' ', $row['news']), 0, 20), ENT_QUOTES).' ...\\\' ?\')'); } Index: pear/Perm_LiveUser/examples/example4/news_new.php diff -u pear/Perm_LiveUser/examples/example4/news_new.php:1.1 pear/Perm_LiveUser/examples/example4/news_new.php:1.2 --- pear/Perm_LiveUser/examples/example4/news_new.php:1.1 Sun Mar 16 17:22:53 2003 +++ pear/Perm_LiveUser/examples/example4/news_new.php Thu Jun 5 12:48:43 2003 @@ -3,7 +3,7 @@ require_once getEnv('DOCUMENT_ROOT') . '/main.inc.php'; // If the user hasn't the right to write news -> access denied. - if (!$LoMa->checkRight(RIGHT_NEWS_NEW, AREA_NEWS)) { + if (!$LU->checkRight(RIGHT_NEWS_NEW)) { $tpl->loadTemplatefile('news_notallowed.tpl.php'); include_once WEB_ROOT . '/finish.inc.php'; exit(); @@ -24,7 +24,7 @@ $tpl->setVariable('script_msg', '<p><font color="red">Only numbers between 1 and 99 are allowed here.</font></p>'); } - elseif (!$LoMa->checkRightLevel(RIGHT_NEWS_NEW, $LoMa->getProperty('permUserId'), $group, AREA_NEWS)) { + elseif (!$LU->checkRightLevel(RIGHT_NEWS_NEW, $LU->getProperty('permUserId'), $group)) { $tpl->setVariable('script_msg', '<p><font color="red">You don\'t have the right to post news for this group.</font></p>'); } @@ -44,7 +44,7 @@ NOW(), '.$db->quote(date('Y.m.d H:i:s', time()+60*60*24*7*$valid_to)).', '.$db->quote(addslashes($news)).', - '.$db->quote($LoMa->getProperty('permUserId')).', + '.$db->quote($LU->getProperty('permUserId')).', '.$group.')'); $tpl->setVariable('script_msg', '<p><b>News has been added.</b></p>'); @@ -69,14 +69,14 @@ } // If the user is member in more than one group, show them. - if (count($LoMa->getProperty('groupIds')) > 1) { + if (count($LU->getProperty('groupIds')) > 1) { $res = $db->query('SELECT group_id, group_comment FROM liveuser_group_names WHERE - group_id IN ('.implode(', ', $LoMa->getProperty('groupIds')).') + group_id IN ('.implode(', ', $LU->getProperty('groupIds')).') ORDER BY group_id'); @@ -92,7 +92,7 @@ } else { $tpl->setCurrentBlock('set_group'); - $tpl->setVariable('group_id', current($LoMa->getProperty('groupIds'))); + $tpl->setVariable('group_id', current($LU->getProperty('groupIds'))); $tpl->parseCurrentBlock(); }