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

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