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 'mysqli://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.             'storage' => array(
  58.                 'dsn' => $dsn,
  59.                 'prefix' => 'liveuser_',
  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.             'passwordEncryptionMode' => 'MD5',
  91.             'storage' => array(
  92.                 'file' => 'Auth_XML.xml',
  93.                 'alias' => array(
  94.                     'auth_user_id' => 'userId',
  95.                     'passwd' => 'password',
  96.                     'lastlogin' => 'lastLogin',
  97.                     'is_active' => 'isActive',
  98.                 ),
  99.             ),
  100.         ),
  101.     ),
  102.     'permContainer' => array(
  103.         'type' => 'Complex',
  104.         'storage' => array(
  105.             'MDB2' => array(
  106.                 'dsn' => $dsn,
  107.                 'prefix' => 'liveuser_',
  108.                 'alias' => array(
  109.                     'perm_users' => 'perm_peoples',
  110.                 ),
  111.             )
  112.          ),
  113.     ),
  114. );
  115.  
  116. require_once 'LiveUser.php';
  117.  
  118. function forceLogin(&$notification)
  119. {
  120.     $liveUserObj =$notification->getNotificationObject();
  121.  
  122.     $username (array_key_exists('username'$_REQUEST)) $_REQUEST['username': null;
  123.     if($username{
  124.         $password (array_key_exists('password'$_REQUEST)) $_REQUEST['password': null;
  125.         $liveUserObj->login($username$password);
  126.     }
  127.     if (!$liveUserObj->isLoggedIn()) {
  128.         showLoginForm($liveUserObj);
  129.     }
  130. }
  131.  
  132. function showLoginForm(&$liveUserObj)
  133. {
  134.     $tpl = new HTML_Template_IT();
  135.     $tpl->loadTemplatefile('loginform.tpl.php');
  136.  
  137.     $tpl->setVariable('form_action'$_SERVER['SCRIPT_NAME']);
  138.  
  139.     if (is_object($liveUserObj)) {
  140.         if ($liveUserObj->getStatus()) {
  141.             switch ($liveUserObj->getStatus()) {
  142.                 case LIVEUSER_STATUS_ISINACTIVE:
  143.                     $tpl->touchBlock('inactive');
  144.                     break;
  145.                 case LIVEUSER_STATUS_IDLED:
  146.                     $tpl->touchBlock('idled');
  147.                     break;
  148.                 case LIVEUSER_STATUS_EXPIRED:
  149.                     $tpl->touchBlock('expired');
  150.                     break;
  151.                 default:
  152.                     $tpl->touchBlock('failure');
  153.                     break;
  154.             }
  155.         }
  156.     }
  157.  
  158.     $tpl->show();
  159.     exit();
  160. }
  161.  
  162. // Create new LiveUser (LiveUser) object.
  163. $LU =LiveUser::factory($LUOptions);
  164. $LU->dispatcher->addObserver('forceLogin''forceLogin');
  165.  
  166. if (!$LU->init()) {
  167.     var_dump($LU->getErrors());
  168.     exit;
  169. }
  170.  
  171. $logout (array_key_exists('logout'$_REQUEST)) $_REQUEST['logout': false;
  172.  
  173. if ($logout{
  174.     $LU->logout(true);
  175.     showLoginForm($LU);
  176. }
  177.  
  178. define('AREA_NEWS',          1);
  179. define('RIGHT_NEWS_NEW',     1);
  180. define('RIGHT_NEWS_CHANGE',  2);
  181. define('RIGHT_NEWS_DELETE',  3);

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