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() function loginAction()
{ {
$form = new LoginForm(); include_once("helper/view.php");
$success=false; $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(); $auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) $this->_redirect('/account'); if ($auth->hasIdentity())
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
if (!$this->login($formData['username'],$formData['password']))
{ {
$this->messenger->addMessage('登录失败,请检查您的用户名和密码。'); view::Post($this,"您已经登录,无需重复登录",-1);
} else $success=true; 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'); $tohref = $this->_request->getParam('href');
if(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login"))
{
$this->view->href = '/';
}
if(!empty($tohref)) if(!empty($tohref))
{ {
$this->_redirect($tohref); $this->view->href = $tohref;
}else{
$this->_redirect($this->_request->getParam('return'));
} }
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; function loadCaptcha()
//$form->populate($formData); {
$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() function logoutAction()

View File

@ -2,22 +2,80 @@
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('用户登录'); $this->headTitle('用户登录');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/register.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/account/login">用户登录</a>'); $this->breadcrumb('<a href="/account/login">用户登录</a>');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<div id="info"> <style>
<img src="/images/Login_title.gif" alt="西部数据中心用户登录" /> .login_box {
<?php echo $this->form;?> 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> </div>
<div id="tool"> <script>
<a href="/account/fetchpwd">忘记密码?</a><a href="/account/register">注册新用户</a> $('#captcha_img').click(function(e) {
</div> changecaptcha();
<?php if (!empty($this->messages)) : ?> });
<div id="message"> function changecaptcha(){
<?php $.ajax({
foreach ($this->messages as $info)echo $info; url:"/account/captcha",
?> data:"<?= time() ?>",
</div> success: function(src){
<?php endif; ?> document.getElementById('captcha_img').src = src;
}
});
}
</script>

View File

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