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

Source for file example.php

Documentation is available at example.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 auth XML driver.
  12.  * No permission management is supported.
  13.  *
  14.  * @author
  15.  * @version $Id: example.php,v 1.9 2004/04/27 00:26:02 mscifo Exp $
  16.  ***/
  17.  
  18. // Get LiveUser configuration array
  19. require_once 'conf.php';
  20.  
  21. if ($xml_is_readable == false || $xml_is_writable == false{
  22.     die('<p style="color: red; text-align: center;">The XML file isn\'t readable/writable. Add the right permissions to it and then try again.</p>');
  23. }
  24.  
  25. // right definitions
  26. define('COOKING',               1);
  27. define('WASHTHEDISHES',         2);
  28. define('WATCHTV',               3);
  29. define('WATCHLATENIGHTTV',      4);
  30. define('USETHECOMPUTER',        5);
  31. define('CONNECTINGTHEINTERNET'6);
  32.  
  33. // The error handling stuff is not needed and used only for debugging
  34. // while LiveUser is not yet mature
  35. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK'eHandler');
  36.  
  37. function eHandler($errObj)
  38. {
  39.     echo('<hr /><span style="color: red">' $errObj->getMessage(':<br />'$errObj->getUserinfo('</span><hr />');
  40. }
  41.  
  42. // Create new LiveUser (LiveUser) object.
  43. $LU =LiveUser::factory($liveuserConfig);
  44.  
  45. // parameters are fetched automatically by LiveUser - see conf setting
  46. $LU->init();
  47. ?>
  48. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  49. <html>
  50. <head>
  51.     <title>Example 1</title>
  52.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  53.     <style type="text/css">
  54.     <!--
  55.     body {
  56.         font-family: Verdana, Arial, Helvetica, sans-serif;
  57.         font-size: 12px;
  58.         color: #000000;
  59.         background-color: #FFFFFF
  60.     }
  61.  
  62.     table {
  63.         border: 1px solid #000;
  64.         border-top: 0px;
  65.         border-right: 0px;
  66.         border-spacing: 0px;
  67.         border-collapse: collapse;
  68.     }
  69.  
  70.     table td {
  71.         width: 100px;
  72.         border-top: 1px solid #000;
  73.         border-right: 1px solid #000;
  74.         padding: 5px;
  75.     }
  76.  
  77.         .center {
  78.            text-align: center;
  79.     }
  80.     .center table {
  81.            margin: auto;
  82.     }
  83.     -->
  84.     </style>
  85. </head>
  86.  
  87. <body>
  88. <?php
  89. // Check if the user has logged in successfully
  90. if (!$LU->isLoggedIn()) {
  91.     if (!empty($_REQUEST)) {
  92. ?>
  93.     <form name="loginform" method="post" action="example.php">
  94.     <div class="center">
  95.         <table width="300" border="0" cellspacing="0" cellpadding="5">
  96.             <tr>
  97.                 <td colspan="2"><b>Example login</b></td>
  98.             </tr>
  99.             <tr>
  100.                 <td>Handle:</td>
  101.                 <td>
  102.                     <input type="text" name="handle" maxlength="80" value="" />
  103.                 </td>
  104.             </tr>
  105.              <tr>
  106.                 <td>Password:</td>
  107.                 <td>
  108.                     <input type="password" name="passwd" maxlength="80" value="" />
  109.                 </td>
  110.             </tr>
  111.             <tr>
  112.                 <td>Remember me:</td>
  113.                 <td>
  114.                     <input type="checkbox" name="remember" />
  115.                 </td>
  116.             </tr>
  117.             <tr>
  118.                 <td colspan="2">
  119.                     <div class="center">
  120.                         <input type="submit" value="Login" />
  121.                     </div>
  122.                 </td>
  123.             </tr>
  124.         </table>
  125.     </div>
  126.     </form>
  127. <?php
  128.     // The user couldn't login, so let's check if the reason was that
  129.     // he's not yet been declared "valid" by an administrator.
  130.     else if ($LU->isInactive()) {
  131. ?>
  132.         <h3>Sorry kid, but one of our admins has yet approved
  133.        your user status. Please be patient. Don't call us -
  134.        we'll call you.</h3>
  135.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  136. <?php
  137.     else {
  138. ?>
  139.       <h3>Sorry, we can't let you in. Check if the spelling of
  140.       your handle and password is correct.</h3>
  141.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  142. <?php
  143.     }
  144. ?>
  145.         <p>&nbsp;</p>
  146.         <p><i>Login Data for this Example:</i></p>
  147.         <table>
  148.             <tr>
  149.                 <td style="text-align: center; font-weight: bold;">Handle</th>
  150.                 <td style="text-align: center; font-weight: bold;">Password</th>
  151.             </tr>
  152.             <tr>
  153.             <td>father</td>
  154.                 <td>father</td>
  155.             </tr>
  156.             <tr>
  157.             <td>mother</td>
  158.                 <td>mother</td>
  159.             </tr>
  160.             <tr>
  161.                 <td>child</td>
  162.                 <td>child</td>
  163.     </tr>
  164.     </table>
  165. <?php
  166. else {
  167. ?>
  168.     <div class="center">
  169.         <h2 style="text-align: center;">User logged in: <?php echo $LU->getProperty('handle')?></h2>
  170.         <p>You can see user's rights in the table.</p>
  171.         <table class="info">
  172.             <tr>
  173.                 <td>right / room</td>
  174.                 <td>kitchen</td>
  175.                 <td>livingroom</td>
  176.                 <td>office</td>
  177.             </tr>
  178. <?php
  179.       //Let's check the rights in the kitchen.
  180. ?>
  181.             <tr>
  182.                 <td>cooking</td>
  183. <?php
  184.     // check whether the user has the required right
  185.     if ($LU->checkRight(COOKING)) {
  186. ?>
  187.                 <td>X</td>
  188. <?php
  189.     else {
  190. ?>
  191.                 <td>&nbsp;</td>
  192. <?php
  193.     }
  194. ?>
  195.                 <td>&nbsp;</td>
  196.                 <td>&nbsp;</td>
  197.             </tr>
  198.             <tr>
  199.                 <td>wash the dishes</td>
  200. <?php
  201.     // check whether the user has the required right
  202.     if ($LU->checkRight(WASHTHEDISHES)) {
  203. ?>
  204.             <td>X</td>
  205. <?php
  206.     else {
  207. ?>
  208.                 <td>&nbsp;</td>
  209. <?php
  210.     }
  211. ?>
  212.                 <td>&nbsp;</td>
  213.                 <td>&nbsp;</td>
  214.             </tr>
  215. <?php
  216.         //Let's check the rights in the livingroom.
  217. ?>
  218.             <tr>
  219.                 <td>watch TV</td>
  220.                 <td>&nbsp;</td>
  221. <?php
  222.     // check whether the user has the required right
  223.     if ($LU->checkRight(WATCHTV)) {
  224. ?>
  225.                 <td>X</td>
  226. <?php
  227.     else {
  228. ?>
  229.                  <td>&nbsp;</td>
  230. <?php
  231.     }
  232. ?>
  233.                 <td>&nbsp;</td>
  234.             </tr>
  235.             <tr>
  236.                 <td>watch latenight TV</td>
  237.                 <td>&nbsp;</td>
  238. <?php
  239.     // check whether the user has the required right
  240.     if ($LU->checkRight(WATCHLATENIGHTTV)) {
  241. ?>
  242.                 <td>X</td>
  243. <?php
  244.     else {
  245. ?>
  246.                 <td>&nbsp;</td>
  247. <?php
  248.     }
  249. ?>
  250.                 <td>&nbsp;</td>
  251.             </tr>
  252. <?php
  253.     //Let's check the rights in the office.
  254. ?>
  255.             <tr>
  256.                 <td>use the computer</td>
  257.                 <td>&nbsp;</td>
  258.                 <td>&nbsp;</td>
  259. <?php
  260.     // check whether the user has the required right
  261.     if ($LU->checkRight(USETHECOMPUTER)) {
  262. ?>
  263.                 <td>X</td>
  264. <?php
  265.     else {
  266. ?>
  267.                 <td>&nbsp;</td>
  268. <?php
  269.     }
  270. ?>
  271.             </tr>
  272.             <tr>
  273.                 <td>connecting to the internet</td>
  274.                 <td>&nbsp;</td>
  275.                 <td>&nbsp;</td>
  276. <?php
  277.     // check whether the user has the required right
  278.     if ($LU->checkRight(CONNECTINGTHEINTERNET)) {
  279. ?>
  280.                 <td>X</td>
  281. <?php
  282.     else {
  283. ?>
  284.                 <td>&nbsp;</td>
  285. <?php
  286.     }
  287. ?>
  288.             </tr>
  289.         </table>
  290.     </div>
  291.     <p align="center"><a href="example.php?logout=1">Logout</a></p>
  292. <?php
  293. }
  294. // Just some more debug output with no further relevance
  295. echo '<hr />Handle:';
  296. print_r($LU->getProperty('handle'));
  297. echo '<br />User Type:';
  298. print_r($LU->getProperty('userType'));
  299.  
  300. echo '<hr /><pre>';
  301. print_r($LU);
  302. echo '<hr />';
  303. print_r($_SESSION);
  304. echo '<hr />';
  305. print_r($_REQUEST);
  306. echo '</pre>';
  307. ?>
  308. </body>
  309. </html>

Documentation generated on Mon, 11 Mar 2019 10:16:04 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.