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.7 2005/03/14 15:51:57 lsmith Exp $
  16.  ***/
  17.  
  18. // Get LiveUser configuration array
  19. require_once 'conf.php';
  20. require 'Log.php';
  21.  
  22. if ($xml_is_readable == false || $xml_is_writable == false{
  23.     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>');
  24. }
  25.  
  26. // The error handling stuff is not needed and used only for debugging
  27. // while LiveUser is not yet mature
  28. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK'eHandler');
  29.  
  30. function eHandler($errObj)
  31. {
  32.     echo('<hr /><span style="color: red">' $errObj->getMessage(':<br />'$errObj->getUserInfo('</span><hr />');
  33. }
  34.  
  35.  
  36. class Log_liveuserlog extends Log
  37. {
  38.     function Log_liveuserlog($name ''$ident ''$conf = array(),
  39.                             $level = PEAR_LOG_DEBUG)
  40.     {
  41.         $this->_id md5(microtime());
  42.         $this->_ident $ident;
  43.         $this->_mask = Log::UPTO($level);
  44.     }
  45.  
  46.     function log($msg$level)
  47.     {
  48.         echo "message: $msg\n";
  49.     }
  50. }
  51.  
  52. class LU_Default_observer
  53. {
  54.     function notify(&$notification)
  55.     {
  56.         echo "observer called on event: " $notification->getNotificationName(" \n";
  57.     }
  58. }
  59.  
  60. // Create new LiveUser (LiveUser) object.
  61. $LU =LiveUser::factory($liveuserConfig);
  62. $logger &Log::factory('liveuserlog');
  63. $LU->addErrorLog($logger);
  64.  
  65. $obs = new LU_Default_observer();
  66.  
  67. $LU->dispatcher->addObserver(array(&$obs'notify'));
  68.  
  69. $username (isset($_REQUEST['handle'])) $_REQUEST['handle': NULL;
  70. $password (isset($_REQUEST['passwd'])) $_REQUEST['passwd': NULL;
  71. $logout (isset($_REQUEST['logout'])) $_REQUEST['logout': false;
  72. $LU->init($username$password$logout);
  73. ?>
  74. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  75. <html>
  76. <head>
  77.     <title>Example 1</title>
  78.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  79.     <style type="text/css">
  80.     <!--
  81.     body {
  82.         font-family: Verdana, Arial, Helvetica, sans-serif;
  83.         font-size: 12px;
  84.         color: #000000;
  85.         background-color: #FFFFFF
  86.     }
  87.  
  88.     table {
  89.         border: 1px solid #000;
  90.         border-top: 0px;
  91.         border-right: 0px;
  92.         border-spacing: 0px;
  93.         border-collapse: collapse;
  94.     }
  95.  
  96.     table td {
  97.         width: 100px;
  98.         border-top: 1px solid #000;
  99.         border-right: 1px solid #000;
  100.         padding: 5px;
  101.     }
  102.  
  103.         .center {
  104.            text-align: center;
  105.     }
  106.     .center table {
  107.            margin: auto;
  108.     }
  109.     -->
  110.     </style>
  111. </head>
  112.  
  113. <body>
  114. <?php
  115. // Check if the user has logged in successfully
  116. if (!$LU->isLoggedIn()) {
  117.     if (!$username{
  118. ?>
  119.     <form name="loginform" method="post" action="example.php">
  120.     <div class="center">
  121.         <table width="300" border="0" cellspacing="0" cellpadding="5">
  122.             <tr>
  123.                 <td colspan="2"><b>Example login</b></td>
  124.             </tr>
  125.             <tr>
  126.                 <td>Handle:</td>
  127.                 <td>
  128.                     <input type="text" name="handle" maxlength="80" value="" />
  129.                 </td>
  130.             </tr>
  131.              <tr>
  132.                 <td>Password:</td>
  133.                 <td>
  134.                     <input type="password" name="passwd" maxlength="80" value="" />
  135.                 </td>
  136.             </tr>
  137.             <tr>
  138.                 <td colspan="2">
  139.                     <div class="center">
  140.                         <input type="submit" value="Login" />
  141.                     </div>
  142.                 </td>
  143.             </tr>
  144.         </table>
  145.     </div>
  146.     </form>
  147. <?php
  148.     // The user couldn't login, so let's check if the reason was that
  149.     // he's not yet been declared "valid" by an administrator.
  150.     else if ($LU->isInactive()) {
  151. ?>
  152.         <h3>Sorry kid, but one of our admins has yet approved
  153.        your user status. Please be patient. Don't call us -
  154.        we'll call you.</h3>
  155.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  156. <?php
  157.     else {
  158. ?>
  159.       <h3>Sorry, we can't let you in. Check if the spelling of
  160.       your handle and password is correct.</h3>
  161.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  162. <?php
  163.     }
  164. ?>
  165.         <p>&nbsp;</p>
  166.         <p><i>Login Data for this Example:</i></p>
  167.         <table>
  168.             <tr>
  169.                 <td style="text-align: center; font-weight: bold;">Handle</th>
  170.                 <td style="text-align: center; font-weight: bold;">Password</th>
  171.             </tr>
  172.             <tr>
  173.             <td>father</td>
  174.                 <td>father</td>
  175.             </tr>
  176.             <tr>
  177.             <td>mother</td>
  178.                 <td>mother</td>
  179.             </tr>
  180.             <tr>
  181.                 <td>child</td>
  182.                 <td>child</td>
  183.     </tr>
  184.     </table>
  185. <?php
  186. else {
  187. ?>
  188.     <h2 align="center">User logged in: <?php echo $LU->getProperty('handle')?></h2>
  189.     <h3>Congrats, you're in</h3>
  190.     <p align="center"><a href="example.php?logout=1">Logout</a></p>
  191. <?php
  192. }
  193. // Just some more debug output with no further relevance
  194. echo '<hr />Handle:';
  195. print_r($LU->getProperty('handle'));
  196. echo '<br />User Type:';
  197. print_r($LU->getProperty('userType'));
  198.  
  199. echo '<hr /><pre>';
  200. print_r($LU);
  201. echo '<hr />';
  202. print_r($_SESSION);
  203. echo '<hr />';
  204. print_r($_REQUEST);
  205. echo '<hr />';
  206. echo 'Observer<br />';
  207. var_dump($GLOBALS['obs']);
  208. echo '</pre>';
  209. ?>
  210. </body>
  211. </html>

Documentation generated on Mon, 11 Mar 2019 14:31:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.