made login session-less

This commit is contained in:
real_nowhereman 2008-03-28 12:25:43 +00:00
parent 52e9109843
commit e201c260f2
2 changed files with 36 additions and 25 deletions

View File

@ -1,15 +1,11 @@
{validate id="userid" message=$lang.login.error.user append="error"}
{validate id="pwd" message=$lang.login.error.pass append="error"}
{validate id="password" message=$lang.login.error.match append="error"}
{include file=shared:errorlist.tpl} {include file=shared:errorlist.tpl}
<form id="login" method="post" action="{$smarty.server.PHP_SELF}?redirect={$smarty.request.redirect}" enctype="multipart/form-data"> <form id="login" method="post" action="{$smarty.server.PHP_SELF}" enctype="multipart/form-data">
<fieldset><legend>{$lang.login.fieldset1}</legend> <fieldset><legend>{$lang.login.fieldset1}</legend>
<p><label for="user">{$lang.login.user}</label><br /> <p><label for="user">{$lang.login.user}</label><br />
<input {$error.user|notempty:'class="field-error"'} type="text" name="user" id="user" /></p> <input {$error.user|notempty:'class="field-error"'} type="text" name="user" id="user" {if $smarty.post.user}value="{$smarty.post.user}"{/if} /></p>
<p><label for="pass">{$lang.login.pass}</label><br /> <p><label for="pass">{$lang.login.pass}</label><br />
<input type="password" {$error.pass|notempty:'class="field-error"'} name="pass" id="pass" /></p> <input type="password" {$error.pass|notempty:'class="field-error"'} name="pass" id="pass" {if $smarty.post.pass}value="{$smarty.post.pass}"{/if} /></p>
</fieldset> </fieldset>
<div class="buttonbar"> <div class="buttonbar">

View File

@ -8,6 +8,36 @@
$tpl = 'default.tpl'; $tpl = 'default.tpl';
function login_validate() {
global $smarty, $lang;
$user = trim(@$_POST['user']);
$pass = trim(@$_POST['pass']);
$error = array();
$lerr =& $lang['login']['error'];
if (!$user) {
$error['user'] = $lerr['user'];
}
if (!$pass) {
$error['pass'] = $lerr['pass'];
}
if (!$error && !user_login($user, $pass)) {
$error['match'] = $lerr['match'];
}
if ($error) {
$smarty->assign('error', $error);
return 0;
}
return 1;
}
function main() { function main() {
global $lang, $smarty; global $lang, $smarty;
@ -54,26 +84,11 @@
} elseif(empty($_POST)) { } elseif(empty($_POST)) {
$content = (SHARED_TPLS . 'login.tpl');
// new form, we (re)set the session data
SmartyValidate::connect($smarty, true);
// register our validators
SmartyValidate::register_validator('userid', 'user', 'notEmpty', false, false, 'trim');
SmartyValidate::register_validator('pwd', 'pass', 'notEmpty', false, false, 'trim');
SmartyValidate::register_validator('password', 'user:pass', 'isValidPassword', false, false);
// display form
$content = (SHARED_TPLS . 'login.tpl');
} else { } else {
// validate after a POST // validate after a POST
SmartyValidate::connect($smarty); if(login_validate()) {
if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect();
// sess_add('login_do', true);
// utils_redirect();
utils_redirect('login.php'); utils_redirect('login.php');
} else { } else {
$smarty->assign($_POST); $smarty->assign($_POST);
$content = (SHARED_TPLS . 'login.tpl'); $content = (SHARED_TPLS . 'login.tpl');
@ -112,4 +127,4 @@
$smarty->display('default.tpl'); $smarty->display('default.tpl');
?> ?>