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

Source for file conf.php

Documentation is available at conf.php

  1. <?php
  2.  
  3. define('EMAIL_WEBMASTER''krausbn@php.net');
  4.  
  5. // PEAR path
  6. //$path_to_liveuser_dir = 'path/to/pear/'.PATH_SEPARATOR;
  7. //ini_set('include_path', $path_to_liveuser_dir . ini_get('include_path'));
  8.  
  9.  
  10. require_once 'PEAR.php';
  11. include_once 'HTML/Template/IT.php';
  12. require_once 'MDB2.php';
  13.  
  14. function php_error_handler($errno$errstr$errfile$errline)
  15. {
  16.     if (error_reporting(&& $errno != 2048{
  17.         $tpl = new HTML_Template_IT();
  18.         $tpl->loadTemplatefile('error-page.tpl.php');
  19.  
  20.         $tpl->setVariable('error_msg'"<b>$errfile ($errline)</b><br />$errstr");
  21.         $tpl->show();
  22.     }
  23. }
  24.  
  25. set_error_handler('php_error_handler');
  26.  
  27. function pear_error_handler($err_obj)
  28. {
  29.     $error_string $err_obj->getMessage('<br />' $err_obj->getUserInfo();
  30.     trigger_error($error_stringE_USER_ERROR);
  31. }
  32.  
  33. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK'pear_error_handler');
  34.  
  35. // Data Source Name (DSN)
  36. //$dsn = '{dbtype}://{user}:{passwd}@{dbhost}/{dbname}';
  37. $dsn 'mysql://root:@localhost/liveuser_test_example4';
  38.  
  39. $db =MDB2::connect($dsntrue);
  40. $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
  41.  
  42.  
  43. $tpl = new HTML_Template_IT();
  44.  
  45. $LUOptions = array(
  46.     'login' => array(
  47.         'force'    => true
  48.      ),
  49.     'logout' => array(
  50.         'destroy'  => true,
  51.      ),
  52.     'authContainers' => array(
  53.         array(
  54.             'type'         => 'MDB2',
  55.             'expireTime'   => 3600,
  56.             'idleTime'     => 1800,
  57.             'allowDuplicateHandles' => 0,
  58.             'storage' => array(
  59.                 'dsn' => $dsn,
  60.                 'alias' => array(
  61.                     'auth_user_id' => 'authUserId',
  62.                     'lastlogin' => 'lastLogin',
  63.                     'is_active' => 'isActive',
  64.                     'owner_user_id' => 'owner_user_id',
  65.                     'owner_group_id' => 'owner_group_id',
  66.                     'users' => 'peoples',
  67.                 ),
  68.                 'fields' => array(
  69.                     'lastlogin' => 'timestamp',
  70.                     'is_active' => 'boolean',
  71.                     'owner_user_id' => 'integer',
  72.                     'owner_group_id' => 'integer',
  73.                 ),
  74.                 'tables' => array(
  75.                     'users' => array(
  76.                         'fields' => array(
  77.                             'lastlogin' => false,
  78.                             'is_active' => false,
  79.                             'owner_user_id' => false,
  80.                             'owner_group_id' => false,
  81.                         ),
  82.                     ),
  83.                 ),
  84.             ),
  85.         ),
  86.         array(
  87.             'type' => 'XML',
  88.             'expireTime'   => 3600,
  89.             'idleTime'     => 1800,
  90.             'allowDuplicateHandles'  => false,
  91.             'passwordEncryptionMode' => 'MD5',
  92.             'storage' => array(
  93.                 'file' => 'Auth_XML.xml',
  94.                 'alias' => array(
  95.                     'auth_user_id' => 'userId',
  96.                     'passwd' => 'password',
  97.                     'lastlogin' => 'lastLogin',
  98.                     'is_active' => 'isActive',
  99.                 ),
  100.             ),
  101.         ),
  102.     ),
  103.     'permContainer' => array(
  104.         'type' => 'Complex',
  105.         'storage' => array(
  106.             'MDB2' => array(
  107.                 'dsn' => $dsn,
  108.                 'prefix' => 'liveuser_',
  109.                 'alias' => array(
  110.                     'perm_users' => 'perm_peoples',
  111.                 ),
  112.             )
  113.          ),
  114.     ),
  115. );
  116.  
  117. require_once 'LiveUser.php';
  118.  
  119. function forceLogin(&$notification)
  120. {
  121.     $liveUserObj =$notification->getNotificationObject();
  122.  
  123.     $username (array_key_exists('username'$_REQUEST)) $_REQUEST['username': null;
  124.     if($username{
  125.         $password (array_key_exists('password'$_REQUEST)) $_REQUEST['password': null;
  126.         $liveUserObj->login($username$password);
  127.     }
  128.     if (!$liveUserObj->isLoggedIn()) {
  129.         showLoginForm($liveUserObj);
  130.     }
  131. }
  132.  
  133. function showLoginForm(&$liveUserObj)
  134. {
  135.     $tpl = new HTML_Template_IT();
  136.     $tpl->loadTemplatefile('loginform.tpl.php');
  137.  
  138.     $tpl->setVariable('form_action'$_SERVER['SCRIPT_NAME']);
  139.  
  140.     if (is_object($liveUserObj)) {
  141.         if ($liveUserObj->getStatus()) {
  142.             switch ($liveUserObj->getStatus()) {
  143.                 case LIVEUSER_STATUS_ISINACTIVE:
  144.                     $tpl->touchBlock('inactive');
  145.                     break;
  146.                 case LIVEUSER_STATUS_IDLED:
  147.                     $tpl->touchBlock('idled');
  148.                     break;
  149.                 case LIVEUSER_STATUS_EXPIRED:
  150.                     $tpl->touchBlock('expired');
  151.                     break;
  152.                 default:
  153.                     $tpl->touchBlock('failure');
  154.                     break;
  155.             }
  156.         }
  157.     }
  158.  
  159.     $tpl->show();
  160.     exit();
  161. }
  162.  
  163. // Create new LiveUser (LiveUser) object.
  164. $LU =LiveUser::factory($LUOptions);
  165. $LU->dispatcher->addObserver('forceLogin''forceLogin');
  166.  
  167. if (!$LU->init()) {
  168.     var_dump($LU->getErrors());
  169.     die();
  170. }
  171.  
  172. $logout (array_key_exists('logout'$_REQUEST)) $_REQUEST['logout': false;
  173.  
  174. if ($logout{
  175.     $LU->logout(true);
  176.     showLoginForm($LU);
  177. }
  178.  
  179. define('AREA_NEWS',          1);
  180. define('RIGHT_NEWS_NEW',     1);
  181. define('RIGHT_NEWS_CHANGE',  2);
  182. define('RIGHT_NEWS_DELETE',  3);

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