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.7 2004/04/27 00:26:30 mscifo 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. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  36. <html>
  37. <head>
  38.     <title>Example Coffeemaker</title>
  39.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  40.     <style type="text/css">
  41.     <!--
  42.     table {
  43.         background-color: #CCCCCC;
  44.         border-color: 1px solid #000;
  45.     }
  46.     body {
  47.         font-family: Verdana, Arial, Helvetica, sans-serif;
  48.         font-size: 12px;
  49.         color: #000000;
  50.         background-color: #FFFFFF
  51.     }
  52.  
  53.     .center {
  54.            text-align: center;
  55.     }
  56.     .center table {
  57.            margin: auto;
  58.     }
  59.     -->
  60.     </style>
  61. </head>
  62.  
  63. <body>
  64.     <h1>Welcome in the Coffeemaker section!</h1>
  65.     <p>&nbsp;</p>
  66. <?php
  67. // check login status
  68. if (!$LU->isLoggedIn()) {
  69.     $target 'coffeemaker.php';
  70.     include_once 'loginscreen.php';
  71.     exit();
  72. else {
  73.     if (!$LU->checkRight(MAKE_COFFEE&& !$LU->checkRight(DRINK_COFFEE)) {
  74. ?>
  75.             <p>Sorry, but you don't have any rights in this section</p>
  76. <?php
  77.     else {
  78.         // Okay, he's in. Now let's display some content dependent of
  79.         // his access rights in our application. Let's pretend the current
  80.         // AuthArea of our application is the Coffeemaker section and we want to
  81.         // know whether to user is allowed to make some coffee
  82.         // (the area is not needed until we won't know whether our user is an area
  83.         // admin).
  84.         if ($LU->checkRight(MAKE_COFFEE)) {
  85. ?>
  86.             <p>Congrats, you're in the Coffeemaker section and have
  87.             the right to make coffee!</p>
  88. <?php
  89.         else {
  90. ?>
  91.             <p>Your coffee tastes so bad, I won't allow you to make some</p>
  92. <?php
  93.         }
  94.         // check if the user is allowed to drink coffee. checkRight will return the level.
  95.         if ($LU->checkRight(DRINK_COFFEE== 1{
  96. ?>
  97.                 <p>Yey ! You can even drink some coffee (but perhaps you should ask your boss first ;-) ))</p>
  98. <?php
  99.         elseif ($LU->checkRight(DRINK_COFFEE== 3{
  100. ?>
  101.                 <p>Hi <?php echo $LU->getProperty('handle')?>! Taste this delicious coffee.</p>
  102. <?php
  103.         else {
  104. ?>
  105.                 <p>Well, sorry dude, you cannot drink in here</p>
  106. <?php
  107.         }
  108.     }
  109. }
  110. ?>
  111.     <p>&nbsp;</p>
  112.     <p class="center"><a href="coffeemaker.php?logout=1">Logout</a></p>
  113. </body>
  114. </html>

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