修改注册页面,增加验证码输入
This commit is contained in:
parent
d60568c77e
commit
0708a3be3b
|
@ -1,6 +1,10 @@
|
|||
<?php
|
||||
use Helpers\View as view;
|
||||
use Mail\Mail;
|
||||
use Open\Client;
|
||||
use Users\Account;
|
||||
use Users\Member;
|
||||
use Helpers\Captcha;
|
||||
use Helpers\View as view;
|
||||
|
||||
class AccountController extends Zend_Controller_Action
|
||||
{
|
||||
|
@ -240,44 +244,32 @@ class AccountController extends Zend_Controller_Action
|
|||
|
||||
function registerAction()
|
||||
{
|
||||
$form = new RegisterForm();
|
||||
$this->view->form = $form;
|
||||
$submit = $this->_getParam("submit");
|
||||
|
||||
if ($this->_request->isPost()) {
|
||||
$formData = $this->_request->getPost();
|
||||
if ($form->isValid($formData)) {
|
||||
$ut = new UsersTable();
|
||||
$u = $ut->createRow();
|
||||
$u->username = $form->getValue('username');
|
||||
$u->password = $form->getValue('password');
|
||||
$u->email=$form->getValue('email');
|
||||
if ($form->getValue('realname')) $u->realname=$form->getValue('realname');
|
||||
if ($form->getValue('phone')) $u->phone=$form->getValue('phone');
|
||||
if ($form->getValue('address')) $u->address=$form->getValue('address');
|
||||
if ($form->getValue('unit')) $u->unit=$form->getValue('unit');
|
||||
if ($form->getValue('project')) $u->project=$form->getValue('project');
|
||||
if ($u->save()) {
|
||||
$captcha = new Captcha();
|
||||
|
||||
//注册邮件
|
||||
$mail_template = "member-register-en";
|
||||
$mail_data = array(
|
||||
'name'=>$formData['username'],
|
||||
);
|
||||
if(!empty($submit))
|
||||
{
|
||||
$account = new Account();
|
||||
$this->view->data = $data = $account->getRegisterParam();
|
||||
$status = $account->register($data);
|
||||
|
||||
$mail = new Mail();
|
||||
|
||||
$mail->loadTemplate($mail_template,$mail_data);
|
||||
$mail->addTo($formData['email'],$formData['username']);
|
||||
$mail->send();
|
||||
|
||||
//自动登录系统
|
||||
$this->login($formData['username'],$formData['password']);
|
||||
$this->_redirect('/');
|
||||
if(isset($status['error']))
|
||||
{
|
||||
$this->view->error = view::Error($status['error']);
|
||||
if(isset($status['place']))
|
||||
{
|
||||
$this->view->place = $status['place'];
|
||||
}
|
||||
$this->view->captcha = $captcha->setCaptcha();
|
||||
}else{
|
||||
view::Post($this,"Thank you for registering at our site.","/");
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
$form->populate($formData);
|
||||
}
|
||||
$this->view->captcha = $captcha->setCaptcha();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function loginAction()
|
||||
|
@ -409,16 +401,18 @@ class AccountController extends Zend_Controller_Action
|
|||
}
|
||||
}
|
||||
|
||||
function captchaAction()
|
||||
public function captchaAction()
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$captcha = $this->loadCaptcha();
|
||||
$url = $this->setCaptcha($captcha,true);
|
||||
|
||||
if(view::isXmlHttpRequest($this))
|
||||
{
|
||||
$captcha = new Captcha();
|
||||
$url = $captcha->setCaptcha();
|
||||
echo $url;
|
||||
return true;
|
||||
}else{
|
||||
echo "bad request!";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
function logoutAction()
|
||||
|
|
|
@ -8,12 +8,101 @@
|
|||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div class="row-fluit">
|
||||
<div class="span12">
|
||||
<img src="/images/pass_login1.gif" /> Agree the terms
|
||||
<img src="/images/pass_pic_arrowhead_2.gif" />
|
||||
<img src="/images/pass_login2.gif" /> Input your base information
|
||||
<img src="/images/pass_pic_arrowhead_2.gif" />
|
||||
<img src="/images/pass_login3.gif" /> Finish register
|
||||
<?php echo $this->form;?>
|
||||
<form class="form-horizontal" method="post" id="register">
|
||||
<?php if(empty($this->error)) { ?>
|
||||
<div class="alert alert-info alert-login">
|
||||
请输入您的基本信息进行注册
|
||||
</div>
|
||||
<? }else{ ?>
|
||||
<?= $this->error ?>
|
||||
<?php } ?>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="username">Username</label>
|
||||
<div class="controls">
|
||||
<input id="username" type="text" value="<?= isset($this->data['username']) ? $this->data['username']:"" ?>" name="username" />
|
||||
<span class="help-inline">(required)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">Password</label>
|
||||
<div class="controls">
|
||||
<input id="password" type="password" value="" name="password" />
|
||||
<span class="help-inline">(required)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="confirm_password">Confirm password</label>
|
||||
<div class="controls">
|
||||
<input id="confirm_password" type="password" value="" name="confirm_password" />
|
||||
<span class="help-inline">(re-typein password)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="email">EMail</label>
|
||||
<div class="controls">
|
||||
<input id="email" type="text" value="<?= isset($this->data['email']) ? $this->data['email']:"" ?>" name="email" />
|
||||
<span class="help-inline">(required)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="realname">Name</label>
|
||||
<div class="controls">
|
||||
<input id="realname" type="text" value="<?= isset($this->data['realname']) ? $this->data['realname']:"" ?>" name="realname" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="phone">Phone</label>
|
||||
<div class="controls">
|
||||
<input id="phone" type="text" value="<?= isset($this->data['phone']) ? $this->data['phone']:"" ?>" name="phone" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="unit">Organization</label>
|
||||
<div class="controls">
|
||||
<input id="unit" type="text" value="<?= isset($this->data['unit']) ? $this->data['unit']:"" ?>" name="unit" class="input-block-level" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="address">Address</label>
|
||||
<div class="controls">
|
||||
<input id="address" type="text" value="<?= isset($this->data['address']) ? $this->data['address']:"" ?>" name="address" class="input-block-level" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="project">Fund</label>
|
||||
<div class="controls">
|
||||
<input id="project" type="text" value="<?= isset($this->data['project']) ? $this->data['project']:"" ?>" name="project" class="input-block-level" />
|
||||
</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="form-actions">
|
||||
<input type="hidden" name="submit" value="1" />
|
||||
<?php if(!empty($this->href)){?>
|
||||
<input type="hidden" name="href" value="<?= $this->href ?>" />
|
||||
<?php }?>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<a href="/account/fetchpwd">forget password?</a>
|
||||
</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>
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
namespace Helpers;
|
||||
|
||||
class Captcha extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public $captcha;
|
||||
|
||||
private $sessionName = "captcha";
|
||||
private $imgDir = "images/captcha";
|
||||
|
||||
function __construct($db = NULL)
|
||||
{
|
||||
$this->loadCaptcha();
|
||||
}
|
||||
|
||||
public function loadCaptcha()
|
||||
{
|
||||
$this->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' => $this->imgDir,
|
||||
'imgUrl' => '/images/captcha',
|
||||
));
|
||||
}
|
||||
|
||||
public function setCaptcha(){
|
||||
if(!is_dir($this->imgDir))
|
||||
{
|
||||
mkdir($this->imgDir);
|
||||
}
|
||||
|
||||
$this->captcha->generate();
|
||||
$_SESSION[$this->sessionName] = $this->captcha->getWord();
|
||||
$url = $this->captcha->getImgUrl()
|
||||
.$this->captcha->getId()
|
||||
.$this->captcha->getSuffix();
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function isValid($captchaword)
|
||||
{
|
||||
if($captchaword == $_SESSION[$this->sessionName])
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +1,38 @@
|
|||
<?php
|
||||
namespace Users;
|
||||
|
||||
use helpers\View as view;
|
||||
use helpers\dbh as dbh;
|
||||
use Users\Member;
|
||||
use Mail\Mail;
|
||||
use \Helpers\View as view;
|
||||
use \Helpers\dbh as dbh;
|
||||
use \Users\Member;
|
||||
use \Mail\Mail;
|
||||
use \Users\Listener\AccountListener;
|
||||
use \Users\Listener\EditListener;
|
||||
use \Users\Listener\PwdListener;
|
||||
|
||||
class Account extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public $memberTable = "users";
|
||||
public $FieldIndex = "id";
|
||||
public $FieldUsername = "username";
|
||||
public $FieldPasword = "password";
|
||||
public $FieldLastlogin = "ts_last_login";
|
||||
public $FieldEmail = "email";
|
||||
public $FieldLastloginIp = "last_login_ip";
|
||||
public $GravatarEmailField = "gravatar_email";
|
||||
public $FieldRealname = "realname";
|
||||
|
||||
public $RoleMember = "member";
|
||||
public $getPwdEmailTemplate = "users-changepassword"; //找回密码的邮件模板名称
|
||||
public $PwdChangedEmailTemplate = "users-password-changed"; //密码修改后的邮件模板
|
||||
|
||||
private $db;
|
||||
protected $events = NULL; //事件
|
||||
private $config;
|
||||
|
||||
function __construct($db = NULL)
|
||||
/*
|
||||
需要挂载的事件分别放在不同的listener中,将各种操作进行模块化细分
|
||||
*/
|
||||
function __construct($initializingListener = TRUE,$db = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
{
|
||||
|
@ -32,7 +43,25 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
if($initializingListener === TRUE)
|
||||
{
|
||||
$this->loadListener();
|
||||
}
|
||||
}
|
||||
|
||||
public function loadListener()
|
||||
{
|
||||
//主要操作,账号注册,登录,设置session等
|
||||
$AccountListener = new AccountListener();
|
||||
@$this->events()->attachAggregate($AccountListener);
|
||||
|
||||
//账户编辑
|
||||
$EditListener = new EditListener();
|
||||
@$this->events()->attachAggregate($EditListener);
|
||||
|
||||
//账户安全性(找回密码)
|
||||
$PwdListener = new PwdListener();
|
||||
@$this->events()->attachAggregate($PwdListener);
|
||||
}
|
||||
|
||||
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
||||
|
@ -60,7 +89,6 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
//注册
|
||||
public function register($data)
|
||||
{
|
||||
|
||||
$params = compact('data');
|
||||
$results = $this->events()->trigger('register.checkParam', $this, $params);
|
||||
$cache_data = $results->bottom();
|
||||
|
@ -145,15 +173,30 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
}//login
|
||||
|
||||
//storeLogin
|
||||
public function storeLogin($data)
|
||||
//将登录信息保存在session和cookie中
|
||||
public function storeLogin($data,$md5verify = true)
|
||||
{
|
||||
$auth = \Zend_Auth::getInstance();
|
||||
$authAdapter = new \Zend_Auth_Adapter_DbTable($this->db);
|
||||
$authAdapter->setTableName($this->memberTable)
|
||||
->setIdentityColumn($this->FieldUsername)
|
||||
->setCredentialColumn($this->FieldPasword);
|
||||
$authAdapter->setIdentity($data[$this->FieldUsername])->setCredential(md5($data[$this->FieldPasword]));
|
||||
|
||||
if($data[$this->FieldPasword] === 0)
|
||||
{
|
||||
$password = "0";
|
||||
}else{
|
||||
if($md5verify == false)
|
||||
{
|
||||
$password = $data[$this->FieldPasword];
|
||||
}else{
|
||||
$password = md5($data[$this->FieldPasword]);
|
||||
}
|
||||
}
|
||||
|
||||
$authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password);
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
|
||||
if ($result->isValid()) {
|
||||
|
||||
$user = $authAdapter->getResultRowObject(null,$this->FieldPasword);
|
||||
|
@ -166,19 +209,34 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
@$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id'));
|
||||
|
||||
return array('success'=>1);
|
||||
}else{
|
||||
return array("error"=>"用户信息验证失败,请重新登录");
|
||||
}
|
||||
return array('error'=>'处理中发现错误,请重试');
|
||||
}
|
||||
|
||||
//注册信息参数
|
||||
public function getParam(\Zend_Controller_Request_Abstract $request)
|
||||
public function getRegisterParam(\Zend_Controller_Request_Abstract $request = NULL)
|
||||
{
|
||||
if(empty($request))
|
||||
{
|
||||
$request = new \Zend_Controller_Request_Http();
|
||||
}
|
||||
$data = array(
|
||||
'username'=>$request->getParam('username'),
|
||||
'password'=>$request->getParam('password'),
|
||||
'confirm_password'=>$request->getParam('confirm_password'),
|
||||
'email'=>$request->getParam('email'),
|
||||
'realname'=>$request->getParam('realname')
|
||||
'username'=>trim($request->getParam('username')),
|
||||
'password'=>trim($request->getParam('password')),
|
||||
'confirm_password'=>trim($request->getParam('confirm_password')),
|
||||
'email' => trim($request->getParam('email')),
|
||||
'realname' => trim($request->getParam('realname')),
|
||||
'phone' => trim($request->getParam('phone')),
|
||||
'unit' => trim($request->getParam('unit')),
|
||||
'address' => trim($request->getParam('address')),
|
||||
'project' => trim($request->getParam('project')),
|
||||
'project_id' => trim($request->getParam('project_id')),
|
||||
'project_type' => trim($request->getParam('project_type')),
|
||||
'project_title' => trim($request->getParam('project_title')),
|
||||
'project_leader'=> trim($request->getParam('project_leader')),
|
||||
'postcode' => trim($request->getParam('postcode')),
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
@ -262,7 +320,7 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
return array('error'=>"此邮箱并未注册",'place'=>'email');
|
||||
}
|
||||
|
||||
$salt = md5($email.'---'.$row['username']);
|
||||
$salt = md5($email.'--'.time().'--'.$row['username']);
|
||||
|
||||
$sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}";
|
||||
$state = $this->db->exec($sql);
|
||||
|
@ -272,15 +330,15 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
return array('error'=>"处理中出现错误,请重试",'place'=>'email');
|
||||
}
|
||||
|
||||
$mail_template = "forgotpassword";
|
||||
$mail_data = array(
|
||||
'name'=>$row['realname'],
|
||||
'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt
|
||||
'link'=> view::getHostLink().'/account/fetchpwd/?salt='.$salt,
|
||||
'site' => $this->config->title->site
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
|
||||
$mail->loadTemplate($mail_template,$mail_data);
|
||||
$mail->loadTemplate($this->getPwdEmailTemplate,$mail_data);
|
||||
$mail->addTo($email,$row['realname']);
|
||||
$mail->send();
|
||||
|
||||
|
@ -316,12 +374,12 @@ class Account extends \Zend_Controller_Plugin_Abstract
|
|||
$sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}";
|
||||
$this->db->exec($sql);
|
||||
|
||||
$mail_template = "getpassworded";
|
||||
$mail_data = array(
|
||||
'name' => $row['realname'],
|
||||
'site' => $this->config->title->site
|
||||
);
|
||||
$mail = new Mail();
|
||||
$mail->loadTemplate($mail_template,$mail_data);
|
||||
$mail->loadTemplate($this->PwdChangedEmailTemplate,$mail_data);
|
||||
$mail->addTo($row['email'],$row['realname']);
|
||||
$mail->send();
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
namespace Users\Listener;
|
||||
|
||||
use Users\Operation\RegisterOperate;
|
||||
use Users\Operation\LoginOperate;
|
||||
use \Users\Operation\RegisterOperate;
|
||||
use \Users\Operation\LoginOperate;
|
||||
|
||||
class AccountListener implements \Zend_EventManager_ListenerAggregate
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Users\Listener;
|
||||
|
||||
use Users\Operation\EditOperate;
|
||||
use \Users\Operation\EditOperate;
|
||||
|
||||
class EditListener implements \Zend_EventManager_ListenerAggregate
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Users\Listener;
|
||||
|
||||
use Users\Operation\PwdOperate;
|
||||
use \Users\Operation\PwdOperate;
|
||||
|
||||
class PwdListener implements \Zend_EventManager_ListenerAggregate
|
||||
{
|
||||
|
|
|
@ -3,9 +3,9 @@ namespace Users;
|
|||
|
||||
class Member
|
||||
{
|
||||
var $ck='DCC3ER4T8L2EFX94OPDF';
|
||||
var $db; //传入PDO对象
|
||||
var $mid; //会员ID
|
||||
public $ck='DCC3ER4T8L2EFX94OPDF';
|
||||
public $db; //传入PDO对象
|
||||
public $mid; //会员ID
|
||||
|
||||
public $scr; //cookie 安全码 $_COOKIE['scr']
|
||||
public $user;//cookie User $_COOKIE['user']
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
namespace Users\Operation;
|
||||
|
||||
use Mail\Mail;
|
||||
use helpers\View as view;
|
||||
use \Mail\Mail;
|
||||
use \Helpers\View as view;
|
||||
|
||||
class EditOperate implements \Users\Event\EditEvent
|
||||
{
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
namespace Users\Operation;
|
||||
|
||||
use Helpers\dbh as dbh;
|
||||
use Users\Gravatar;
|
||||
use \Helpers\dbh as dbh;
|
||||
use \Users\Gravatar;
|
||||
|
||||
class LoginOperate implements \Users\Event\LoginEvent
|
||||
{
|
||||
|
@ -45,9 +45,9 @@ class LoginOperate implements \Users\Event\LoginEvent
|
|||
|
||||
if(!empty($data['username']))
|
||||
{
|
||||
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username']))
|
||||
if(mb_strlen($data['username'])<2)
|
||||
{
|
||||
return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username');
|
||||
return array('error'=>"用户名长度应该大于两个字符",'place'=>'username');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ class LoginOperate implements \Users\Event\LoginEvent
|
|||
|
||||
$update = array(
|
||||
$this->FieldLastlogin => date("Y-m-d H:i:s"),
|
||||
$this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"]
|
||||
//$this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"]
|
||||
);
|
||||
|
||||
$dbh = new dbh();
|
||||
|
@ -106,6 +106,10 @@ class LoginOperate implements \Users\Event\LoginEvent
|
|||
|
||||
}//loginSuccess
|
||||
|
||||
|
||||
//检查token表记录
|
||||
public function checkOAuthToken()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -58,6 +58,11 @@ class PwdOperate implements \Users\Event\PwdEvent
|
|||
{
|
||||
$data = $e->getParam('data');
|
||||
|
||||
if(empty($data['salt']))
|
||||
{
|
||||
return array('error'=>"密钥不正确,请重新申请","place"=>'salt');
|
||||
}
|
||||
|
||||
if(empty($data['username']))
|
||||
{
|
||||
return array('error'=>"请输入用户名",'place'=>'username');
|
||||
|
@ -70,12 +75,12 @@ class PwdOperate implements \Users\Event\PwdEvent
|
|||
|
||||
if(strlen($data['password']) < 6)
|
||||
{
|
||||
return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>'password');
|
||||
return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password');
|
||||
}
|
||||
|
||||
if(strlen($data['password']) > 14)
|
||||
{
|
||||
return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>'password');
|
||||
return array('error'=>"密码太长,请不要超过14位",'place'=>'password');
|
||||
}
|
||||
|
||||
if(empty($data['confirm_password']))
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
namespace Users\Operation;
|
||||
|
||||
use Mail\Mail;
|
||||
use Helpers\View as view;
|
||||
use \Mail\Mail;
|
||||
use \Helpers\View as view;
|
||||
|
||||
class RegisterOperate implements \Users\Event\RegisterEvent
|
||||
{
|
||||
private $db; //传入PDO对象
|
||||
public $tbl_member = "tbl_member";
|
||||
public $tbl_member = "users";
|
||||
public $FieldUsername = "username";
|
||||
public $FieldPasword = "password";
|
||||
public $FieldLastlogin = "ts_last_login";
|
||||
|
@ -17,6 +17,8 @@ class RegisterOperate implements \Users\Event\RegisterEvent
|
|||
private $DefaultFetchMode = \PDO::FETCH_BOTH; //默认检索模式,防止出现sdtClass错误
|
||||
private $config; //全局配置
|
||||
|
||||
private $lang = "en";
|
||||
|
||||
function __construct($db = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
|
@ -35,65 +37,63 @@ class RegisterOperate implements \Users\Event\RegisterEvent
|
|||
|
||||
if(!is_array($data))
|
||||
{
|
||||
return "参数错误";
|
||||
return "Parameter Problems";
|
||||
}
|
||||
|
||||
if(empty($data['username']))
|
||||
{
|
||||
return array('error'=>"请输入用户名",'place'=>'username');
|
||||
return array('error'=>"Username is required",'place'=>'username');
|
||||
}
|
||||
|
||||
if(!empty($data['username']))
|
||||
{
|
||||
if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username']))
|
||||
if(!preg_match("/[0-9a-zA-Z\xa0-\xff_]{2,25}/",$data['username']))
|
||||
{
|
||||
return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到16个字符之间",'place'=>'username');
|
||||
return array('error'=>"Username is too long or too short (maximum is 25 characters,minimum is 3 characters)",'place'=>'username');
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($data['password']))
|
||||
{
|
||||
return array('error'=>"请输入密码",'place'=>'password');
|
||||
return array('error'=>"Password is required",'place'=>'password');
|
||||
}
|
||||
|
||||
if(strlen($data['password']) < 6)
|
||||
{
|
||||
return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password');
|
||||
return array('error'=>"Password is too short(minimum is 6 characters)",'place'=>'password');
|
||||
}
|
||||
|
||||
if(strlen($data['password']) > 14)
|
||||
{
|
||||
return array('error'=>"密码太长,请不要超过14位",'place'=>'password');
|
||||
return array('error'=>"Password is too long (maximum is 15 characters)",'place'=>'password');
|
||||
}
|
||||
|
||||
if(empty($data['confirm_password']))
|
||||
{
|
||||
return array('error'=>"请再次输入密码已确认输入正确",'place'=>'confirm_password');
|
||||
return array('error'=>"Password confirmation is required",'place'=>'confirm_password');
|
||||
}
|
||||
|
||||
if(md5($data['password']) != md5($data['confirm_password']))
|
||||
{
|
||||
return array('error'=>"两次输入的密码不同,请重新输入",'place'=>'confirm_password');
|
||||
return array('error'=>"Passwords do not match",'place'=>'confirm_password');
|
||||
}
|
||||
|
||||
if(empty($data['email']))
|
||||
{
|
||||
return array('error'=>"请输入电子邮箱,作为找回密码和接受通知的联系方式",'place'=>'email');
|
||||
return array('error'=>"Email is required",'place'=>'email');
|
||||
}
|
||||
|
||||
if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email']))
|
||||
{
|
||||
return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place'=>'email');
|
||||
return array('error'=>"Please enter a valid email address",'place'=>'email');
|
||||
}
|
||||
|
||||
if(empty($data['realname']))
|
||||
if(!empty($data['realname']))
|
||||
{
|
||||
return array('error'=>"请输入姓名",'place'=>'realname');
|
||||
}
|
||||
|
||||
if(mb_strlen($data['realname'],"UTF-8")>10 )
|
||||
{
|
||||
return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname');
|
||||
return array('error'=>"Realname is too long (maximum is 15 characters)",'place'=>'realname');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -105,7 +105,7 @@ class RegisterOperate implements \Users\Event\RegisterEvent
|
|||
|
||||
if(!is_array($data))
|
||||
{
|
||||
return "用户信息验证失败,请重新尝试";
|
||||
return "Parameter Problems";
|
||||
}
|
||||
|
||||
$sql = "SELECT id,{$this->FieldUsername},{$this->FieldEmail} FROM ".$this->tbl_member." WHERE {$this->FieldUsername}='{$data['username']}' OR {$this->FieldEmail}='{$data['email']}'";
|
||||
|
@ -118,15 +118,15 @@ class RegisterOperate implements \Users\Event\RegisterEvent
|
|||
{
|
||||
if($row[$this->FieldUsername] == $data['username'])
|
||||
{
|
||||
return array('error'=>'您的用户名已经注册过账号,您是否<a href="/account/forgotpassword">忘记了密码?</a>','place'=>'username');
|
||||
return array('error'=>'your username already exists ,<a href="/account/fetchpwd">forget password?</a>','place'=>'username');
|
||||
}
|
||||
|
||||
if($row[$this->FieldEmail] == $data['email'])
|
||||
{
|
||||
return array('error'=>'您的邮箱已经注册过账号,请换一个邮箱','place'=>'email');
|
||||
return array('error'=>'your email already used','place'=>'email');
|
||||
}
|
||||
|
||||
return array('error'=>'您的用户名或邮箱已经使用过,注册新账号请换一个用户名');
|
||||
return array('error'=>'your username already exists or email already used');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -148,10 +148,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent
|
|||
return false;
|
||||
}
|
||||
|
||||
$mail_template = "register";
|
||||
$mail_template = "member-register";
|
||||
$mail_data = array(
|
||||
'name'=>$data['realname'],
|
||||
'content'=>$this->getMailContent()
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
|
@ -166,25 +165,11 @@ class RegisterOperate implements \Users\Event\RegisterEvent
|
|||
//邮件内容
|
||||
public function getMailContent()
|
||||
{
|
||||
$sql = "SELECT v.id,v.title,v.thumb,v.status,v.content,m.realname,m.username FROM tbl_voice v
|
||||
LEFT JOIN tbl_member m ON v.userid = m.id
|
||||
WHERE v.status > 0
|
||||
ORDER BY v.id DESC
|
||||
LIMIT 5";
|
||||
$rs = $this->db->query($sql);
|
||||
$latest = $rs->fetchAll();
|
||||
|
||||
|
||||
$content = "";
|
||||
|
||||
foreach($latest as $k=>$v)
|
||||
{
|
||||
if($v['thumb'] != '[]')
|
||||
{
|
||||
$thumb = json_decode($v['thumb'],true);
|
||||
$text = mb_strlen($v['content'],"UTF-8") > 100 ? mb_substr($v['content'],0,100,"UTF-8") : $v['content'];
|
||||
$content .= '<p style="width:100%;overflow:hidden;"><img src="http://www.msgfm.com'.$this->config->upload->urlbase.$thumb[0]['thumb'][400]['url'].'" height="100" style="float:left;margin-right:10px;" />'.$v['title']. ' / ' .$v['realname'].'<br />'.$text.'<br /><a href="http://www.msgfm.com/voice/'.$v['id'].'.html">查看播放</a></p>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $content;
|
||||
}//getMailContent();
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
namespace Users;
|
||||
|
||||
use \Helpers\View as view;
|
||||
use \Helpers\dbh as dbh;
|
||||
use \Users\Account;
|
||||
use \Helpers\Table;
|
||||
|
||||
/*
|
||||
对 \Users\Account 再次进行抽象,满足后台调用的需求,屏蔽一些错误等等
|
||||
!!!!important!!!!大部分操作直接来自 \User\Account,慎重修改
|
||||
*/
|
||||
class Users extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
private $db;
|
||||
protected $events = NULL; //事件
|
||||
public $table;
|
||||
|
||||
public $account;
|
||||
|
||||
function __construct($accountClass = FALSE,$db = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
$this->table = new Table();
|
||||
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
if($accountClass === TRUE)
|
||||
{
|
||||
$this->account = new Account();
|
||||
}
|
||||
}
|
||||
|
||||
//通过email地址返回用户信息是否存在
|
||||
public function userExists($email = NULL)
|
||||
{
|
||||
if(empty($email))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty($this->account))
|
||||
{
|
||||
$account = new Account(FALSE);
|
||||
}else{
|
||||
$account = $this->account;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM {$account->memberTable} WHERE {$account->FieldEmail}=? LIMIT 1";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($email));
|
||||
$row = $sth->fetch();
|
||||
|
||||
unset($account);
|
||||
|
||||
if(isset($row['id']) && !empty($row['id']))
|
||||
{
|
||||
return $row;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue