merge heihedata branch r3739.

This commit is contained in:
wlx 2013-06-20 14:39:11 +00:00
parent 47eacc7c14
commit 7052e0b5a5
3 changed files with 223 additions and 61 deletions

View File

@ -285,46 +285,149 @@ class AccountController extends Zend_Controller_Action
function loginAction()
{
$form = new LoginForm();
include_once("helper/view.php");
$success=false;
$message='';
$this->view->form = $form;
$options = array(
'module' => $this->_request->getModuleName(),
'controller' => $this->_request->getControllerName(),
'action' => $this->_request->getActionName(),
);
$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']))
if ($auth->hasIdentity())
{
$this->messenger->addMessage('登录失败,请检查您的用户名和密码。');
} else $success=true;
view::Post($this,"您已经登录,无需重复登录",-1);
return 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(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login"))
{
$this->view->href = '/';
}
if(!empty($tohref))
{
$this->_redirect($tohref);
}else{
$this->_redirect($this->_request->getParam('return'));
$this->view->href = $tohref;
}
if($_SERVER['REQUEST_URI']!='/account/login')
$captcha = $this->loadCaptcha();
$submit = $this->_getParam("submit");
if(!empty($submit))
{
$this->_redirect($_SERVER['REQUEST_URI']);
$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);
}
}
} else {
//$formData['redirect'] = $redirect;
//$form->populate($formData);
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()

View File

@ -2,22 +2,80 @@
$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;?>
<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>
<div id="tool">
<a href="/account/fetchpwd">忘记密码?</a><a href="/account/register">注册新用户</a>
<? }else{ ?>
<div class="alert alert-error alert-login">
<?= $this->error ?>
</div>
<?php if (!empty($this->messages)) : ?>
<div id="message">
<?php
foreach ($this->messages as $info)echo $info;
?>
<?php } ?>
<div class="control-group">
<label class="control-label" for="username">用户名</label>
<div class="controls">
<input id="username" type="text" value="" name="username" />
</div>
<?php endif; ?>
</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>

View File

@ -34,6 +34,7 @@
// in order to gain privilege
$this->acl->allow('guest', 'account', array('login',
'logout',
'captcha',
'fetchpwd',
'register',
'registercomplete'));