LiveUser
[ class tree: LiveUser ] [ index: LiveUser ] [ all elements ]

Source for file coffeemaker.php

Documentation is available at coffeemaker.php

  1. <?php
  2. /**
  3.  * Test for the LiveUser class
  4.  * ===============================
  5.  *
  6.  * This example sets up an authorization system using the LiveUser
  7.  * class. You don't have to use this to use the LiveUser class(es), but
  8.  * this way you don't need to take care of the login-process, storing
  9.  * the user object in a session and more...
  10.  *
  11.  * This example is intended to be used with the DB_Medium Perm driver.
  12.  *
  13.  * @version $Id: coffeemaker.php,v 1.8 2004/10/23 14:04:06 arnaud Exp $
  14.  ***/
  15.  
  16. // right definitions
  17. define('MAKE_COFFEE'6);
  18. define('DRINK_COFFEE'7);
  19.  
  20. // Include configuration.
  21. require_once 'conf.php';
  22.  
  23. // The error handling stuff is not needed and used only for debugging
  24. // while LiveUser is not yet mature
  25. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK'eHandler');
  26.  
  27. function eHandler($errObj)
  28. {
  29.     echo('<hr /><span style="color: red;">' $errObj->getMessage(':<br />' $errObj->getUserinfo('</span><hr />');
  30. }
  31.  
  32. // Create new LiveUser object
  33. $LU LiveUser::factory($liveuserConfig);
  34.  
  35. if (!$LU{
  36.     die('An unknown error occurred');
  37. }
  38.  
  39. // we have an error stack
  40. if (is_array($LU)) {
  41.     echo 'One or more errors occurred, here is the array';
  42.     print_r($LU);
  43. }
  44.  
  45. ?>
  46. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  47. <html>
  48. <head>
  49.     <title>Example Coffeemaker</title>
  50.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  51.     <style type="text/css">
  52.     <!--
  53.     table {
  54.         background-color: #CCCCCC;
  55.         border-color: 1px solid #000;
  56.     }
  57.     body {
  58.         font-family: Verdana, Arial, Helvetica, sans-serif;
  59.         font-size: 12px;
  60.         color: #000000;
  61.         background-color: #FFFFFF
  62.     }
  63.  
  64.     .center {
  65.            text-align: center;
  66.     }
  67.     .center table {
  68.            margin: auto;
  69.     }
  70.     -->
  71.     </style>
  72. </head>
  73.  
  74. <body>
  75.     <h1>Welcome in the Coffeemaker section!</h1>
  76.     <p>&nbsp;</p>
  77. <?php
  78. // check login status
  79. if (!$LU->isLoggedIn()) {
  80.     $target 'coffeemaker.php';
  81.     include_once 'loginscreen.php';
  82.     exit();
  83. else {
  84.     if (!$LU->checkRight(MAKE_COFFEE&& !$LU->checkRight(DRINK_COFFEE)) {
  85. ?>
  86.             <p>Sorry, but you don't have any rights in this section</p>
  87. <?php
  88.     else {
  89.         // Okay, he's in. Now let's display some content dependent of
  90.         // his access rights in our application. Let's pretend the current
  91.         // AuthArea of our application is the Coffeemaker section and we want to
  92.         // know whether to user is allowed to make some coffee
  93.         // (the area is not needed until we won't know whether our user is an area
  94.         // admin).
  95.         if ($LU->checkRight(MAKE_COFFEE)) {
  96. ?>
  97.             <p>Congrats, you're in the Coffeemaker section and have
  98.             the right to make coffee!</p>
  99. <?php
  100.         else {
  101. ?>
  102.             <p>Your coffee tastes so bad, I won't allow you to make some</p>
  103. <?php
  104.         }
  105.         // check if the user is allowed to drink coffee. checkRight will return the level.
  106.         if ($LU->checkRight(DRINK_COFFEE== 1{
  107. ?>
  108.                 <p>Yey ! You can even drink some coffee (but perhaps you should ask your boss first ;-) ))</p>
  109. <?php
  110.         elseif ($LU->checkRight(DRINK_COFFEE== 3{
  111. ?>
  112.                 <p>Hi <?php echo $LU->getProperty('handle')?>! Taste this delicious coffee.</p>
  113. <?php
  114.         else {
  115. ?>
  116.                 <p>Well, sorry dude, you cannot drink in here</p>
  117. <?php
  118.         }
  119.     }
  120. }
  121. ?>
  122.     <p>&nbsp;</p>
  123.     <p class="center"><a href="coffeemaker.php?logout=1">Logout</a></p>
  124. </body>
  125. </html>

Documentation generated on Mon, 11 Mar 2019 13:57:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.