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

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