您的位置:首页 > 其它

原来的笔记-用LiveUser来处理登录认证

2008-05-11 10:50 507 查看

用LiveUser来处理登录认证

Posted 三月 9th, 2007 by stone5

pear

require_once("conf.php");
require_once("login.php");

page_top();//显示页头
if (!$LU->isLoggedIn())//是否登录
{
echo 'Login';
show_login();//显示登录表单界面
}
else
{
echo 'LiveUser Example';//下面显示登录用户的各个属性而已
echo 'Logout';
echo 'Welcome ' . $LU->getProperty('handle') . '!';
echo 'Here is the contents of the "liveuser_users" table:';
echo '

';
echo '
auth_user_id:' . $LU->getProperty('auth_user_id') . '
';
echo '

handle:' . $LU->getProperty('handle') . '
';
echo '

passwd:' . $LU->getProperty('passwd') . '
';
echo '

owner_user_id:' . $LU->getProperty('owner_user_id') . '
';
echo '

owner_group_id:' . $LU->getProperty('owner_group_id') . '
';
echo '

lastlogin:' . date('d.m.Y H:i', $LU->getProperty('lastlogin')) . '
';
echo '

is_active:' . $LU->getProperty('passwd') . '
';
echo '

email: ' . $LU->getProperty('email') . '
';
echo '

';
}
page_bottom();
?>
//login.php的文件内容
<?php

function page_top()
{
echo '';
echo '';
echo '';
}

function page_bottom()
{
echo '';
}

function show_login()
{
ini_set("include_path", '../../libs/PEAR/' . PATH_SEPARATOR . ini_get("include_path"));
require_once ("HTML/QuickForm.php");//用了QuickForm包
echo 'Please log in to access this page';
$form =& new HTML_Quickform('logon', 'post');

$renderer =& $form->defaultRenderer();//用这个来构QuickForm包的模板,偶还是暂时不清楚
$renderer->setElementTemplate('
{label}
(*)
{error}
{element}');

$note='(*) Mandatory';
$form->setRequiredNote($note);//不解,下次在QuickForm中学

$form->addElement('text', 'handle', 'Userid', array('class'=>'text'));//有了上面的模板,这边增加元素就好了,呵呵
$form->addRule('handle', 'Userid is mandatory', 'required');

$form->addElement('password', 'passwd', 'Password', array('class'=>'text'));
$form->addRule('passwd','Password is mandatory', 'required');
$form->registerRule('check_pswd', 'callback', 'is_pswd_ok', $form);
$form->addRule('passwd', 'Logon failed', 'check_pswd');

$form->addElement('advcheckbox', 'rememberMe', '', ' Remember me',
array('class'=>'text'), array(false,true));

$form->addElement('submit', 'btnSubmit', 'Login');

if (!$form->validate())
{
$form->display();
}
}

function is_pswd_ok(&$passwd)
{
$LU->login($LU->getProperty('handle'),$LU->getProperty('passwd'));//处理登录的过程呀
if ($LU->isLoggedIn())
{
return true;
}
else
{
return false;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐