1<?php 2 3define('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 9error_reporting(1803); 10 11require_once 'PEAR.php'; 12include_once 'HTML/Template/IT.php'; 13require_once 'MDB2.php'; 14 15function php_error_handler($errno, $errstr, $errfile, $errline) 16{ 17 if (error_reporting() && $errno != 2048) { 18 $tpl = new HTML_Template_IT(); 19 $tpl->loadTemplatefile('error-page.tpl.php'); 20 21 $tpl->setVariable('error_msg', "<b>$errfile ($errline)</b><br />$errstr"); 22 $tpl->show(); 23 } 24} 25 26set_error_handler('php_error_handler'); 27 28function pear_error_handler($err_obj) 29{ 30 $error_string = $err_obj->getMessage() . '<br />' . $err_obj->getUserInfo(); 31 trigger_error($error_string, E_USER_ERROR); 32} 33 34PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_error_handler'); 35 36// Data Source Name (DSN) 37//$dsn = '{dbtype}://{user}:{passwd}@{dbhost}/{dbname}'; 38$dsn = 'mysqli://root:@localhost/liveuser_test_example4'; 39 40$db =& MDB2::connect($dsn, true); 41$db->setFetchMode(MDB2_FETCHMODE_ASSOC); 42 43 44$tpl = new HTML_Template_IT(); 45 46$LUOptions = array( 47 'login' => array( 48 'force' => true 49 ), 50 'logout' => array( 51 'destroy' => true, 52 ), 53 'authContainers' => array( 54 array( 55 'type' => 'MDB2', 56 'expireTime' => 3600, 57 'idleTime' => 1800, 58 'storage' => array( 59 'dsn' => $dsn, 60 'prefix' => 'liveuser_', 61 'alias' => array( 62 'auth_user_id' => 'authUserId', 63 'lastlogin' => 'lastLogin', 64 'is_active' => 'isActive', 65 'owner_user_id' => 'owner_user_id', 66 'owner_group_id' => 'owner_group_id', 67 'users' => 'peoples', 68 ), 69 'fields' => array( 70 'lastlogin' => 'timestamp', 71 'is_active' => 'boolean', 72 'owner_user_id' => 'integer', 73 'owner_group_id' => 'integer', 74 ), 75 'tables' => array( 76 'users' => array( 77 'fields' => array( 78 'lastlogin' => false, 79 'is_active' => false, 80 'owner_user_id' => false, 81 'owner_group_id' => false, 82 ), 83 ), 84 ), 85 ), 86 ), 87 array( 88 'type' => 'XML', 89 'expireTime' => 3600, 90 'idleTime' => 1800, 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 117require_once 'LiveUser.php'; 118 119function 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 133function 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// We�ll only use the auth container, permissions are not used. 165$LU =& LiveUser::factory($LUOptions); 166$LU->dispatcher->addObserver('forceLogin', 'forceLogin'); 167 168if (!$LU->init()) { 169 var_dump($LU->getErrors()); 170 exit; 171} 172 173$logout = (array_key_exists('logout', $_REQUEST)) ? $_REQUEST['logout'] : false; 174 175if ($logout) { 176 $LU->logout(true); 177 showLoginForm($LU); 178} 179 180define('AREA_NEWS', 1); 181define('RIGHT_NEWS_NEW', 1); 182define('RIGHT_NEWS_CHANGE', 2); 183define('RIGHT_NEWS_DELETE', 3);