merge heihedata branch to trunk from r4153 to r4159

This commit is contained in:
wlx 2013-12-27 13:44:12 +00:00
parent ee4d32a372
commit 6db4162f06
8 changed files with 235 additions and 149 deletions

View File

@ -66,7 +66,7 @@ class AccountController extends Zend_Controller_Action
"国家级国家自然科学基金" => "国家级国家自然科学基金", "国家级国家自然科学基金" => "国家级国家自然科学基金",
"国际合作项目"=>"国际合作项目", "国际合作项目"=>"国际合作项目",
"省部级项目" => "省部级项目", "省部级项目" => "省部级项目",
"其他项目工程" => "其他项目工程" "其他项目工程" => "其他项目工程",
); );
$submit = $this->_getParam('submit'); $submit = $this->_getParam('submit');
@ -250,44 +250,31 @@ class AccountController extends Zend_Controller_Action
function registerAction() function registerAction()
{ {
$form = new RegisterForm(); $order = new \Order\Order();
$this->view->form = $form;
if ($this->_request->isPost()) { $this->view->projectType = array_merge(array(""=>""),$order->projectType);
$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()) {
//注册邮件 $submit = $this->_getParam("submit");
$mail_template = "member-register";
$mail_data = array(
'name'=>$formData['username'],
);
$mail = new Mail(); if(!empty($submit))
{
$account = new Account();
$this->view->data = $data = $account->getRegisterParam();
$status = $account->register($data);
$mail->loadTemplate($mail_template,$mail_data); if(isset($status['error']))
$mail->addTo($formData['email'],$formData['username']); {
$mail->send(); $this->view->error = view::Error($status['error']);
if(isset($status['place']))
//自动登录系统 {
$this->login($formData['username'],$formData['password']); $this->view->place = $status['place'];
$this->_redirect('/');
} }
}else{ }else{
$form->populate($formData); view::Post($this,"注册成功!","/");
return true;
} }
} }
} }
function loginAction() function loginAction()
@ -328,6 +315,13 @@ class AccountController extends Zend_Controller_Action
$password = trim($this->_request->getParam('password')); $password = trim($this->_request->getParam('password'));
$captchaword = trim($this->_request->getParam('captcha')); $captchaword = trim($this->_request->getParam('captcha'));
if($captcha->isValid($captchaword) !== true)
{
$this->view->error = view::Error("验证码错误");
$this->view->captcha = $captcha->setCaptcha();
return true;
}
$account = new Account(); $account = new Account();
$status = $account->login(array( $status = $account->login(array(
'username' => $username, 'username' => $username,
@ -336,23 +330,18 @@ class AccountController extends Zend_Controller_Action
if(isset($status['error'])) if(isset($status['error']))
{ {
$this->view->error = $status; $this->view->error = view::Error($status['error']);
$this->view->captcha = $captcha->setCaptcha();
return true;
}
if(!$captcha->isValid($captchaword))
{
$this->view->error = "验证码错误";
$this->view->captcha = $captcha->setCaptcha(); $this->view->captcha = $captcha->setCaptcha();
return true; return true;
} }
view::Post($this,"登录成功,正在跳转",$tohref); view::Post($this,"登录成功,正在跳转",$tohref);
return true; return true;
}else{
$this->view->captcha = $captcha->setCaptcha();
} }
$this->view->captcha = $captcha->setCaptcha();
} }
public function captchaAction() public function captchaAction()

View File

@ -6,21 +6,6 @@
$this->breadcrumb('<a href="/account/login">用户登录</a>'); $this->breadcrumb('<a href="/account/login">用户登录</a>');
$this->breadcrumb()->setSeparator(' > '); $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"> <div class="row-fluid">
<form class="form-horizontal" method="post"> <form class="form-horizontal" method="post">
<?php if(empty($this->error)) { ?> <?php if(empty($this->error)) { ?>
@ -28,9 +13,7 @@
请输入用户名和密码登录 请输入用户名和密码登录
</div> </div>
<? }else{ ?> <? }else{ ?>
<div class="alert alert-error alert-login"> <?= $this->error ?>
<?= $this->error['error'] ?>
</div>
<?php } ?> <?php } ?>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="username">用户名</label> <label class="control-label" for="username">用户名</label>

View File

@ -8,12 +8,134 @@
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<div class="row-fluit"> <div class="row-fluit">
<div class="span12"> <form class="form-horizontal" method="post" id="register">
<img src="/images/pass_login1.gif" />&nbsp;确认服务条款&nbsp;&nbsp; <?php if(empty($this->error)) { ?>
<img src="/images/pass_pic_arrowhead_2.gif" />&nbsp;&nbsp; <div class="alert alert-info alert-login">
<img src="/images/pass_login2.gif" />&nbsp;填写基本信息&nbsp;&nbsp; 请输入您的基本信息进行注册
<img src="/images/pass_pic_arrowhead_2.gif" />&nbsp;&nbsp; </div>
<img src="/images/pass_login3.gif" />&nbsp;注册完成 <? }else{ ?>
<?php echo $this->form;?> <?= $this->error ?>
<?php } ?>
<div class="control-group">
<label class="control-label" for="username">用户名</label>
<div class="controls">
<input id="username" type="text" value="<?= isset($this->data['username']) ? $this->data['username']:"" ?>" name="username" />
<span class="help-inline">(必填)</span>
</div> </div>
</div> </div>
<div class="control-group">
<label class="control-label" for="password">密码</label>
<div class="controls">
<input id="password" type="password" value="" name="password" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="confirm_password">确认密码</label>
<div class="controls">
<input id="confirm_password" type="password" value="" name="confirm_password" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">E-Mail</label>
<div class="controls">
<input id="email" type="text" value="<?= isset($this->data['email']) ? $this->data['email']:"" ?>" name="email" />
<span class="help-inline">(必填)</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="realname">真实姓名</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">电话</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">单位</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">联系地址</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_id">项目编号</label>
<div class="controls">
<input id="project_id" type="text" value="<?= isset($this->data['project_id']) ? $this->data['project_id']:"" ?>" name="project_id" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="project_leader">项目负责人</label>
<div class="controls">
<input id="project_leader" type="text" value="<?= isset($this->data['project_leader']) ? $this->data['project_leader']:"" ?>" name="project_leader" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="project_type">项目类型</label>
<div class="controls">
<select id="project_type" name="project_type">
<?php if(!empty($this->projectType)) { ?>
<?php foreach($this->projectType as $k=>$v) { ?>
<?php if(empty($this->data['project_type'])) {?>
<?php if($v == "") { ?>
<option value="<?= $v ?>" selected="selected"><?= $k ?></option>
<?php }else { ?>
<option value="<?= $v ?>"><?= $k ?></option>
<?php }
} else {?>
<?php if($v == $this->data['project_type']) { ?>
<option value="<?= $v ?>" selected="selected"><?= $k ?></option>
<?php }else { ?>
<option value="<?= $v ?>"><?= $k ?></option>
<?php }
}?>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="project_title">项目名称</label>
<div class="controls">
<input id="project_title" type="text" value="<?= isset($this->data['project_title']) ? $this->data['project_title']:"" ?>" name="project_title" class="input-block-level" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="project">项目介绍</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="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">提交</button>
<a href="/account/fetchpwd">忘记密码?</a>
</div>
</form>
</div>
<?php if(!empty($this->place)){ ?>
<script>
var input = $("#register input[name=<?= $this->place ?>]");
input.parent('div').parent('div.control-group').addClass('error');
input.focus();
input.blur(function(e){
if(input.val() != '')
{
input.parent('div').parent('div.control-group').removeClass('error');
}
});
</script>
<?php } ?>

View File

@ -1,4 +1,8 @@
<?php <?php
use Users\Member;
use Users\Account;
use Helpers\View as view;
class CustomControllerAclManager extends Zend_Controller_Plugin_Abstract class CustomControllerAclManager extends Zend_Controller_Plugin_Abstract
{ {
// default user role if not logged or (or invalid role found) // default user role if not logged or (or invalid role found)
@ -72,31 +76,23 @@
if(!$this->auth->hasIdentity()) if(!$this->auth->hasIdentity())
{ {
$mb = new member(); $member = new Member();
$mb->db=$this->db;
if($mb->checkcookie()) if($member->checkcookie())
{
$data = array(
'username' => $member->user,
'password' => $member->srpwd
);
$account = new Account();
$status = $account->storeLogin($data,false);
if(isset($status['error']))
{ {
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable($this->db); $auth->clearIdentity();
$authAdapter->setTableName('users') Member::flushcookie();
->setIdentityColumn('username')
->setCredentialColumn('password');
$authAdapter->setIdentity($mb->user)->setCredential($mb->srpwd);
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$data = $authAdapter->getResultRowObject(null,'password');
//头像
include_once("Avatar.php");
$avatar = new Avatar();
$data->avatar = $avatar->Get($data->email,40);
//组ID
include_once("Users.php");
$usr = new Users($this->db);
$data->gid = $usr->getGroup($data->id);
$auth->getStorage()->write($data);
$this->db->query("update users set ts_last_login=now() where username=?",array($mb->user));
} }
} }
} }

View File

@ -55,7 +55,7 @@ class View extends \Zend_Controller_Plugin_Abstract
$html = '<div class="alert alert-block fade in '.$AlertType.'" id="Alert-error-box">'."\r\n"; $html = '<div class="alert alert-block fade in '.$AlertType.'" id="Alert-error-box">'."\r\n";
$html.= '<a class="close" data-dismiss="alert" href="#">×</a>'."\r\n"; $html.= '<a class="close" data-dismiss="alert" href="#">×</a>'."\r\n";
if(!is_array($content)) { if(!is_array($content)) {
$html.= '<h4 class="alert-heading">'.$content.'</h4>'."\r\n"; $html.= ''.$content.''."\r\n";
}else{ }else{
$html.= '<ul>'."\r\n"; $html.= '<ul>'."\r\n";
foreach($content as $v) { foreach($content as $v) {

View File

@ -216,14 +216,27 @@ class Account extends \Zend_Controller_Plugin_Abstract
} }
//注册信息参数 //注册信息参数
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( $data = array(
'username'=>$request->getParam('username'), 'username'=>trim($request->getParam('username')),
'password'=>$request->getParam('password'), 'password'=>trim($request->getParam('password')),
'confirm_password'=>$request->getParam('confirm_password'), 'confirm_password'=>trim($request->getParam('confirm_password')),
'email'=>$request->getParam('email'), 'email' => trim($request->getParam('email')),
'realname'=>$request->getParam('realname') '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; return $data;
} }

View File

@ -3,9 +3,9 @@ namespace Users;
class Member class Member
{ {
var $ck='DCC3ER4T8L2EFX94OPDF'; public $ck='DCC3ER4T8L2EFX94OPDF';
var $db; //传入PDO对象 public $db; //传入PDO对象
var $mid; //会员ID public $mid; //会员ID
public $scr; //cookie 安全码 $_COOKIE['scr'] public $scr; //cookie 安全码 $_COOKIE['scr']
public $user;//cookie User $_COOKIE['user'] public $user;//cookie User $_COOKIE['user']

View File

@ -7,7 +7,7 @@ use \Helpers\View as view;
class RegisterOperate implements \Users\Event\RegisterEvent class RegisterOperate implements \Users\Event\RegisterEvent
{ {
private $db; //传入PDO对象 private $db; //传入PDO对象
public $tbl_member = "tbl_member"; public $tbl_member = "users";
public $FieldUsername = "username"; public $FieldUsername = "username";
public $FieldPasword = "password"; public $FieldPasword = "password";
public $FieldLastlogin = "ts_last_login"; public $FieldLastlogin = "ts_last_login";
@ -45,9 +45,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent
if(!empty($data['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'=>"用户名只能包含字母汉字数字和下划线并且长度在2到26个字符之间",'place'=>'username');
} }
} }
@ -83,18 +83,16 @@ class RegisterOperate implements \Users\Event\RegisterEvent
if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email'])) if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email']))
{ {
return array('error'=>"请输入正确的电子邮件推荐使用QQ邮箱和Gmail邮箱",'place'=>'email'); return array('error'=>"请输入正确的电子邮件地址",'place'=>'email');
} }
if(empty($data['realname'])) if(!empty($data['realname']))
{ {
return array('error'=>"请输入姓名",'place'=>'realname');
}
if(mb_strlen($data['realname'],"UTF-8")>10 ) if(mb_strlen($data['realname'],"UTF-8")>10 )
{ {
return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname'); return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname');
} }
}
return true; return true;
}//checkParam }//checkParam
@ -118,7 +116,7 @@ class RegisterOperate implements \Users\Event\RegisterEvent
{ {
if($row[$this->FieldUsername] == $data['username']) if($row[$this->FieldUsername] == $data['username'])
{ {
return array('error'=>'您的用户名已经注册过账号,您是否<a href="/account/forgotpassword">忘记了密码?</a>','place'=>'username'); return array('error'=>'您的用户名已经注册过账号,您是否<a href="/account/fetchpwd">忘记了密码?</a>','place'=>'username');
} }
if($row[$this->FieldEmail] == $data['email']) if($row[$this->FieldEmail] == $data['email'])
@ -148,10 +146,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent
return false; return false;
} }
$mail_template = "register"; $mail_template = "member-register";
$mail_data = array( $mail_data = array(
'name'=>$data['realname'], 'name'=>$data['realname'],
'content'=>$this->getMailContent()
); );
$mail = new Mail(); $mail = new Mail();
@ -166,25 +163,11 @@ class RegisterOperate implements \Users\Event\RegisterEvent
//邮件内容 //邮件内容
public function getMailContent() 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 = ""; $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; return $content;
}//getMailContent(); }//getMailContent();