新增分站登陆时的验证码功能。

This commit is contained in:
Li Heng 2013-12-26 09:04:34 +00:00
parent 9779a0bebe
commit 5529995c9c
2 changed files with 37 additions and 36 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
use Helpers\View; use Helpers\View;
use Helpers\Curl; use Helpers\Curl;
use Helpers\Captcha;
use Users\Member; use Users\Member;
use Users\Account; use Users\Account;
use Users\Users; use Users\Users;
@ -291,7 +292,6 @@ class AccountController extends Zend_Controller_Action
function loginAction() function loginAction()
{ {
$success=false; $success=false;
$options = array( $options = array(
@ -323,11 +323,13 @@ class AccountController extends Zend_Controller_Action
{ {
$this->view->href = $tohref; $this->view->href = $tohref;
} }
$captcha = new Captcha();
//登录表单提交 //登录表单提交
if(!$this->_getParam('submit')) if(!$this->_getParam('submit'))
{ {
$this->view->captcha = $captcha->setCaptcha();
return false; return false;
} }
@ -335,13 +337,17 @@ class AccountController extends Zend_Controller_Action
$param = array( $param = array(
'username' => $this->_getParam('username'), 'username' => $this->_getParam('username'),
'password' => $this->_getParam('password') 'password' => $this->_getParam('password'),
'captchaword' => trim($this->_request->getParam('captcha'))
); );
$captchaword = $param['captchaword'];
#用户名校验 #用户名校验
if(strlen($param['username'])<6) if(strlen($param['username'])<6)
{ {
$this->view->error = '用户名不能少于6个字符'; $this->view->error = '用户名不能少于6个字符';
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
@ -349,12 +355,14 @@ class AccountController extends Zend_Controller_Action
{ {
$this->view->error = '用户名不能超过20个字符'; $this->view->error = '用户名不能超过20个字符';
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,19}$/",$param['username'])) if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,19}$/",$param['username']))
{ {
$this->view->error = '用户名只能包含英文字母及数字'; $this->view->error = '用户名只能包含英文字母及数字';
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
@ -365,27 +373,51 @@ class AccountController extends Zend_Controller_Action
if(preg_match($match,$param['password']) ) if(preg_match($match,$param['password']) )
{ {
$this->view->error = '密码中包含非法字符,请重新输入'; $this->view->error = '密码中包含非法字符,请重新输入';
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
if(empty($param['password'])) if(empty($param['password']))
{ {
$this->view->error = '请输入密码'; $this->view->error = '请输入密码';
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
if(strlen($param['password'])<6) if(strlen($param['password'])<6)
{ {
$this->view->error ='密码太短'; $this->view->error ='密码太短';
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
if(strlen($param['password'])>20) if(strlen($param['password'])>20)
{ {
$this->view->error ="密码长度不能超过20个字符"; $this->view->error ="密码长度不能超过20个字符";
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
#验证码校验
if(empty($captchaword))
{
$this->view->error = "请输入验证码";
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(!isset($_SESSION['captcha']))
{
$_SESSION['captcha'] = md5(time());
}
if ($captchaword != $_SESSION['captcha']) {
$this->view->captcha = $captcha->setCaptcha();
$this->view->error = "验证码错误";
return true;
}
$encoded_param = json_encode($param,JSON_NUMERIC_CHECK); $encoded_param = json_encode($param,JSON_NUMERIC_CHECK);
$encoded_param = \Helpers\MCrypt::encrypt($encoded_param,"DY7567"); $encoded_param = \Helpers\MCrypt::encrypt($encoded_param,"DY7567");
@ -414,41 +446,10 @@ class AccountController extends Zend_Controller_Action
view::Post($this,"登录成功!",$tohref); view::Post($this,"登录成功!",$tohref);
} }
$this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
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() function captchaAction()
{ {

View File

@ -7,7 +7,7 @@ class IndexController extends Zend_Controller_Action
$this->view->config = Zend_Registry::get('config'); $this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db'); $this->db=Zend_Registry::get('db');
$this->view->theme = new Theme(); $this->view->theme = new Theme();
$this->view->main_nav_pageID = "index"; # $this->view->main_nav_pageID = "index";
} }
function indexAction() function indexAction()