修改登录页面表单,增加鼠标单击切换验证码的功能
This commit is contained in:
parent
7ec4679db8
commit
97b8d9292f
|
@ -285,47 +285,150 @@ class AccountController extends Zend_Controller_Action
|
|||
|
||||
function loginAction()
|
||||
{
|
||||
$form = new LoginForm();
|
||||
$success=false;
|
||||
$message='';
|
||||
$this->view->form = $form;
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity()) $this->_redirect('/account');
|
||||
if ($this->_request->isPost()) {
|
||||
$formData = $this->_request->getPost();
|
||||
if ($form->isValid($formData)) {
|
||||
if (!$this->login($formData['username'],$formData['password']))
|
||||
{
|
||||
$this->messenger->addMessage('登录失败,请检查您的用户名和密码。');
|
||||
} else $success=true;
|
||||
}
|
||||
|
||||
if(!$success) {
|
||||
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
|
||||
$flashMessenger->setNamespace('actionErrors');
|
||||
$flashMessenger->addMessage($message);
|
||||
$this->_redirect('/account/login');
|
||||
} else
|
||||
{
|
||||
$tohref = $this->_request->getParam('href');
|
||||
if(!empty($tohref))
|
||||
{
|
||||
$this->_redirect($tohref);
|
||||
}else{
|
||||
$this->_redirect($this->_request->getParam('return'));
|
||||
}
|
||||
include_once("helper/view.php");
|
||||
|
||||
$success=false;
|
||||
|
||||
$options = array(
|
||||
'module' => $this->_request->getModuleName(),
|
||||
'controller' => $this->_request->getControllerName(),
|
||||
'action' => $this->_request->getActionName(),
|
||||
);
|
||||
|
||||
if($_SERVER['REQUEST_URI']!='/account/login')
|
||||
{
|
||||
$this->_redirect($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
//$formData['redirect'] = $redirect;
|
||||
//$form->populate($formData);
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity())
|
||||
{
|
||||
view::Post($this,"您已经登录,无需重复登录",-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
$tohref = $this->_request->getParam('href');
|
||||
|
||||
if(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login"))
|
||||
{
|
||||
$this->view->href = '/';
|
||||
}
|
||||
|
||||
if(!empty($tohref))
|
||||
{
|
||||
$this->view->href = $tohref;
|
||||
}
|
||||
|
||||
$captcha = $this->loadCaptcha();
|
||||
|
||||
$submit = $this->_getParam("submit");
|
||||
if(!empty($submit))
|
||||
{
|
||||
$username = trim($this->_request->getParam('username'));
|
||||
$password = trim($this->_request->getParam('password'));
|
||||
$captchaword = trim($this->_request->getParam('captcha'));
|
||||
|
||||
if(empty($username))
|
||||
{
|
||||
$this->setCaptcha($captcha);
|
||||
$this->view->error = "请输入用户名";
|
||||
return true;
|
||||
}
|
||||
|
||||
if(empty($password))
|
||||
{
|
||||
$this->setCaptcha($captcha);
|
||||
$this->view->error = "请输入密码";
|
||||
return true;
|
||||
}
|
||||
|
||||
if(empty($captchaword))
|
||||
{
|
||||
$this->setCaptcha($captchaword);
|
||||
$this->view->error = "请输入验证码";
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!isset($_SESSION['captcha']))
|
||||
{
|
||||
$_SESSION['captcha'] = md5(time());
|
||||
}
|
||||
|
||||
if ($captchaword != $_SESSION['captcha']) {
|
||||
$this->setCaptcha($captcha);
|
||||
$this->view->error = "验证码错误";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$this->login($username,$password))
|
||||
{
|
||||
$this->setCaptcha($captcha);
|
||||
$this->view->error = "用户名或密码错误";
|
||||
$this->view->userid = $username;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(!empty($tohref))
|
||||
{
|
||||
view::Post($this,"登录成功,正在跳转",$tohref);
|
||||
return true;
|
||||
}
|
||||
|
||||
if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")
|
||||
{
|
||||
view::Post($this,"登录成功,正在跳转",'/');
|
||||
return true;
|
||||
}else{
|
||||
view::Post($this,"登录成功,正在跳转",$_SERVER['REQUEST_URI']);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$this->setCaptcha($captcha);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function loadCaptcha()
|
||||
{
|
||||
$captcha = new Zend_Captcha_Image(array(
|
||||
'captcha' => 'Image',
|
||||
'wordLen' => 4,
|
||||
'fontsize'=>16,
|
||||
'width' => 100,
|
||||
'height' => 38,
|
||||
'dotNoiseLevel'=>2,
|
||||
'lineNoiseLevel'=>1,
|
||||
'timeout' => 300,
|
||||
'font' => '../data/fonts/ggbi.ttf',
|
||||
'imgDir' => 'vdimg/',
|
||||
'imgUrl' => '/vdimg',
|
||||
));
|
||||
return $captcha;
|
||||
}
|
||||
|
||||
function setCaptcha(Zend_Captcha_Image $captcha,$ajax = false){
|
||||
$captcha->generate();
|
||||
$_SESSION['captcha'] = $captcha->getWord();
|
||||
$url = $captcha->getImgUrl()
|
||||
.$captcha->getId()
|
||||
.$captcha->getSuffix();
|
||||
if(!$ajax)
|
||||
{
|
||||
$this->view->captcha = $url;
|
||||
}else{
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
function captchaAction()
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$captcha = $this->loadCaptcha();
|
||||
$url = $this->setCaptcha($captcha,true);
|
||||
|
||||
echo $url;
|
||||
return true;
|
||||
}
|
||||
|
||||
function logoutAction()
|
||||
{
|
||||
|
|
|
@ -1,23 +1,81 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('用户登录');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/register.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/account/login">用户登录</a>');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div id="info">
|
||||
<img src="/images/Login_title.gif" alt="西部数据中心用户登录" />
|
||||
<?php echo $this->form;?>
|
||||
</div>
|
||||
<div id="tool">
|
||||
<a href="/account/fetchpwd">忘记密码?</a><a href="/account/register">注册新用户</a>
|
||||
</div>
|
||||
<?php if (!empty($this->messages)) : ?>
|
||||
<div id="message">
|
||||
<?php
|
||||
foreach ($this->messages as $info)echo $info;
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('用户登录');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/account/login">用户登录</a>');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<style>
|
||||
.login_box {
|
||||
max-width: 300px;
|
||||
padding: 19px 29px 29px;
|
||||
margin: 0 auto 20px;
|
||||
background-color: #fff;
|
||||
border: 1px solid #e5e5e5;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
|
||||
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
|
||||
box-shadow: 0 1px 2px rgba(0,0,0,.05);
|
||||
}
|
||||
</style>
|
||||
<div class="row-fluid">
|
||||
<form class="form-horizontal" method="post">
|
||||
<?php if(empty($this->error)) { ?>
|
||||
<div class="alert alert-info alert-login">
|
||||
请输入用户名和密码登录
|
||||
</div>
|
||||
<? }else{ ?>
|
||||
<div class="alert alert-error alert-login">
|
||||
<?= $this->error ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="username">用户名</label>
|
||||
<div class="controls">
|
||||
<input id="username" type="text" value="" name="username" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">密码</label>
|
||||
<div class="controls">
|
||||
<input id="password" type="password" value="" name="password" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="captcha">验证码</label>
|
||||
<div class="controls">
|
||||
<input id="captcha" type="text" value="" name="captcha" />
|
||||
<img id="captcha_img" src="<?php echo $this->captcha ?>" style="cursor:pointer" />
|
||||
<a href="javascript:void(0);" onclick="changecaptcha()">看不清?</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<input type="hidden" name="submit" value="1" />
|
||||
<?php if(!empty($this->href)){?>
|
||||
<input type="hidden" name="href" value="<?= $this->href ?>" />
|
||||
<?php }?>
|
||||
<label class="checkbox"><input id="remember" type="checkbox" value="1" name="remember">记住我</label>
|
||||
<button type="submit" class="btn">登录</button>
|
||||
<a href="/account/fetchpwd">忘记密码?</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$('#captcha_img').click(function(e) {
|
||||
changecaptcha();
|
||||
});
|
||||
function changecaptcha(){
|
||||
$.ajax({
|
||||
url:"/account/captcha",
|
||||
data:"<?= time() ?>",
|
||||
success: function(src){
|
||||
document.getElementById('captcha_img').src = src;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -34,6 +34,7 @@
|
|||
// in order to gain privilege
|
||||
$this->acl->allow('guest', 'account', array('login',
|
||||
'logout',
|
||||
'captcha',
|
||||
'fetchpwd',
|
||||
'register',
|
||||
'registercomplete'));
|
||||
|
|
Loading…
Reference in New Issue