恢复用户信息编辑功能

This commit is contained in:
Li Jianxuan 2014-07-15 08:04:23 +00:00
parent b5b672588c
commit 64222944d0
2 changed files with 551 additions and 357 deletions

View File

@ -1,275 +1,469 @@
<?php <?php
use Helpers\View as view; use Helpers\View as view;
use Users\Account; use Users\Account;
use Users\Gravatar; use Users\Gravatar;
class AccountController extends Zend_Controller_Action class AccountController extends Zend_Controller_Action
{ {
private $memberTable = "tbl_member"; private $memberTable = "tbl_member";
private $FieldUsername = "username"; private $FieldUsername = "username";
private $FieldPasword = "password"; private $FieldPasword = "password";
private $FieldLastlogin = "ts_last_login"; private $FieldLastlogin = "ts_last_login";
private $FieldEmail = "email"; private $FieldEmail = "email";
private $FieldLastloginIp = "last_login_ip"; private $FieldLastloginIp = "last_login_ip";
function preDispatch() function preDispatch()
{ {
$this->view->config = Zend_Registry::get('config'); $this->view->config = Zend_Registry::get('config');
$this->_request->setParam('return', $this->_request->getServer('REQUEST_URI')); $this->_request->setParam('return', $this->_request->getServer('REQUEST_URI'));
$this->db=Zend_Registry::get('db'); $this->db=Zend_Registry::get('db');
$this->view->Theme = new Theme(); $this->view->Theme = new Theme();
} }
function indexAction() function indexAction()
{ {
$submit = $this->_getParam('submit'); $this->view->pageID = "account-index";
$account = new Account(); include_once("Users.php");
$usr = new Users($this->db);
if(!empty($submit))
{ $auth = Zend_Auth::getInstance();
$data = $account->getEditParam($this->_request); if($auth->hasIdentity())
$Listener = new EditListener(); {
@$account->events()->attachAggregate($Listener); $user = $auth->getIdentity();
$this->view->section = $type = $this->_getParam('type'); $uid = $user->id;
$status = $account->edit($data,$type); }
if($status !== true)
{ include_once("Avatar.php");
$this->view->error = view::Error($status); $avatar = new Avatar();
}else{ $this->view->avatar = $avatar->Get($user->email,140);
$this->view->error = view::Error("修改成功","alert-success");
} $this->view->info = $usr->getUserInfo($uid);
} }
$user = $account->getAccountInfo(); function loginAction()
$av = new Gravatar(); {
$this->view->avatar = $av->Get($user['email'],100); $request = new \Zend_Controller_Request_Http();
$this->view->user = $user; if($request->isXmlHttpRequest())
} {
$this->_helper->layout->disableLayout();
function loginAction() $this->_helper->viewRenderer->setNoRender();
{
$request = new \Zend_Controller_Request_Http(); $data = $this->_getParam('data');
if($request->isXmlHttpRequest()) if(empty($data))
{ {
$this->_helper->layout->disableLayout(); $this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
$this->_helper->viewRenderer->setNoRender(); }
$data = $this->_getParam('data'); $data = \Helpers\MCrypt::decrypt($data,"DY7567");
if(empty($data)) $data = json_decode($data,true);
{
$this->jsonexit(array('error'=>'服务器掉链子了,请重试')); $account = new Account();
} $result = $account->login($data,true);
$data = \Helpers\MCrypt::decrypt($data,"DY7567"); if(!empty($result))
$data = json_decode($data,true); {
$content = json_encode($result,JSON_NUMERIC_CHECK);
$account = new Account(); echo \Helpers\MCrypt::encrypt($content,"CH6668");
$result = $account->login($data,true); return true;
}
if(!empty($result))
{ $this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
$content = json_encode($result,JSON_NUMERIC_CHECK);
echo \Helpers\MCrypt::encrypt($content,"CH6668"); return true;
return true; }
}
$success=false;
$this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
$options = array(
return true; 'module' => $this->_request->getModuleName(),
} 'controller' => $this->_request->getControllerName(),
'action' => $this->_request->getActionName(),
$success=false; );
$options = array( $auth = Zend_Auth::getInstance();
'module' => $this->_request->getModuleName(), if ($auth->hasIdentity())
'controller' => $this->_request->getControllerName(), {
'action' => $this->_request->getActionName(), if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")
); {
$this->_redirect("/");
$auth = Zend_Auth::getInstance(); }else{
if ($auth->hasIdentity()) $this->_redirect($_SERVER['REQUEST_URI']);
{ }
if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login") }
{
$this->_redirect("/"); $tohref = $this->_request->getParam('href');
}else{
$this->_redirect($_SERVER['REQUEST_URI']); if($_SERVER['REQUEST_URI'] !== "/account/login")
} {
} $this->view->href = $_SERVER['REQUEST_URI'];
}else{
$tohref = $this->_request->getParam('href'); $this->view->href = "/";
}
if($_SERVER['REQUEST_URI'] !== "/account/login")
{ if(!empty($tohref))
$this->view->href = $_SERVER['REQUEST_URI']; {
}else{ $this->view->href = $tohref;
$this->view->href = "/"; }
}
$submit = $this->_getParam("submit");
if(!empty($tohref))
{ if(!empty($submit))
$this->view->href = $tohref; {
} $data = array(
'username' => $this->_getParam('username'),
$submit = $this->_getParam("submit"); 'password' => $this->_getParam('password')
);
if(!empty($submit))
{ $account = new Account();
$data = array( $result = $account->login($data);
'username' => $this->_getParam('username'),
'password' => $this->_getParam('password') if(!empty($result))
); {
if(isset($result['error']))
$account = new Account(); {
$result = $account->login($data); $this->view->error = $result['error'];
return true;
if(!empty($result)) }
{ if(isset($result['success']))
if(isset($result['error'])) {
{ $this->_redirect($this->view->href);
$this->view->error = $result['error']; return true;
return true; }
} }else{
if(isset($result['success'])) $this->view->error = "处理中出现问题";
{ return true;
$this->_redirect($this->view->href); }
return true; }
} }//登陆
}else{
$this->view->error = "处理中出现问题"; public function jsonexit($data){
return true; $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
} return true;
} }
}//登陆
function registerAction()
public function jsonexit($data){ {
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $request = new \Zend_Controller_Request_Http();
return true; if($request->isXmlHttpRequest())
} {
$this->_helper->layout->disableLayout();
function registerAction() $this->_helper->viewRenderer->setNoRender();
{
$request = new \Zend_Controller_Request_Http(); $account = new Account();
if($request->isXmlHttpRequest()) $data = $account->getParam($this->_request);
{
$this->_helper->layout->disableLayout(); $result = $account->register($data);
$this->_helper->viewRenderer->setNoRender();
if(!empty($result))
$account = new Account(); {
$data = $account->getParam($this->_request); $this->jsonexit($result);
return true;
$result = $account->register($data); }
if(!empty($result)) $this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试'));
{
$this->jsonexit($result); return true;
return true; }else{
} //$this->_helper->layout->disableLayout();
}
$this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试'));
return true; $success=false;
}else{
//$this->_helper->layout->disableLayout(); $auth = Zend_Auth::getInstance();
} if ($auth->hasIdentity())
$this->_redirect('/');
$success=false; $submit = $this->_getParam('submit');
if(!empty($submit))
$auth = Zend_Auth::getInstance(); {
if ($auth->hasIdentity()) $account = new Account();
$this->_redirect('/'); $this->view->data = $data = $account->getParam($this->_request);
$result = $account->register($data);
$submit = $this->_getParam('submit');
if(!empty($submit)) if(!empty($result))
{ {
$account = new Account(); if(isset($result['error']))
$this->view->data = $data = $account->getParam($this->_request); {
$result = $account->register($data); $this->view->place = $result['place'];
$this->view->error = $result['error'];
if(!empty($result)) return true;
{ }
if(isset($result['error'])) if(isset($result['success']))
{ {
$this->view->place = $result['place']; $this->_redirect('/');
$this->view->error = $result['error']; return true;
return true; }
} }else{
if(isset($result['success'])) $this->view->error = "处理中出现问题";
{ return true;
$this->_redirect('/'); }
return true; }
} }//用户注册
}else{
$this->view->error = "处理中出现问题"; //退出登录
return true; function logoutAction()
} {
} $this->_helper->layout->disableLayout();
}//用户注册 $this->_helper->viewRenderer->setNoRender();
//退出登录 $auth = Zend_Auth::getInstance();
function logoutAction()
{ if ($auth->hasIdentity())
$this->_helper->layout->disableLayout(); {
$this->_helper->viewRenderer->setNoRender(); $auth->clearIdentity();
Users\Member::flushcookie();
$auth = Zend_Auth::getInstance(); $this->_redirect('/');
}
if ($auth->hasIdentity()) }
{
$auth->clearIdentity(); //找回密码
Users\Member::flushcookie(); function forgotpasswordAction()
$this->_redirect('/'); {
} $this->_helper->layout->disableLayout();
}
$submit = $this->_getParam('submit');
//找回密码
function forgotpasswordAction() if(!empty($submit))
{ {
$this->_helper->layout->disableLayout(); $email = $this->_getParam('email');
$account = new Account();
$submit = $this->_getParam('submit'); $status = $account->getMyPassword($email);
if(isset($status['error']) && !empty($status['error']))
if(!empty($submit)) {
{ $this->view->error = $status['error'];
$email = $this->_getParam('email'); }else{
$account = new Account(); $this->view->msg = "申请成功!请在您的邮箱中查看密码重置邮件";
$status = $account->getMyPassword($email); }
if(isset($status['error']) && !empty($status['error'])) }
{ }
$this->view->error = $status['error'];
}else{ //重置密码
$this->view->msg = "申请成功!请在您的邮箱中查看密码重置邮件"; function getpasswordAction()
} {
} $this->_helper->layout->disableLayout();
}
$submit = $this->_getParam('submit');
//重置密码
function getpasswordAction() if(!empty($submit))
{ {
$this->_helper->layout->disableLayout(); $data = array(
'username' => $this->_getParam('username'),
$submit = $this->_getParam('submit'); 'password' => $this->_getParam('password'),
'confirm_password' => $this->_getParam('confirm_password'),
if(!empty($submit)) 'salt' => $this->_getParam('salt')
{ );
$data = array( $account = new Account();
'username' => $this->_getParam('username'), $status = $account->resetPassword($data);
'password' => $this->_getParam('password'), if(isset($status['error']) && !empty($status['error']))
'confirm_password' => $this->_getParam('confirm_password'), {
'salt' => $this->_getParam('salt') $this->view->error = $status['error'];
); }else{
$account = new Account(); $this->view->msg = "您的密码已经成功更改,<a href='/account/login'>请点击这里登陆</a>";
$status = $account->resetPassword($data); }
if(isset($status['error']) && !empty($status['error'])) }
{ }//getpasswordAction()
$this->view->error = $status['error'];
}else{ function editAction()
$this->view->msg = "您的密码已经成功更改,<a href='/account/login'>请点击这里登陆</a>"; {
} $this->view->pageID = "account-edit";
}
}//getpasswordAction() include_once("Users.php");
$usr = new Users($this->db);
}
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$uid = $user->id;
}
include_once("Avatar.php");
$avatar = new Avatar();
$this->view->avatar = $avatar->Get($user->email,140);
$this->view->projectType = array(
"" => '',
"国家973计划项目课题" => "国家973计划项目课题",
"国家863计划课题"=>"国家863计划课题",
"国家级科技支撑课题" => "国家级科技支撑课题",
"国家级科技重大专项" => "国家级科技重大专项",
"国家级国家重大工程" => "国家级国家重大工程",
"国家级国家自然科学基金" => "国家级国家自然科学基金",
"国际合作项目"=>"国际合作项目",
"省部级项目" => "省部级项目",
"其他项目工程" => "其他项目工程",
);
$submit = $this->_getParam('submit');
if(!empty($submit))
{
$data = $this->AccountEditParamFilter();
if($this->db->update("users",$data,"id=$uid"))
{
$this->view->AlertType = "alert-success";
$this->view->msg = "修改成功!";
$this->view->jump_url = "/account/edit";
return true;
}else{
$this->view->AlertType = "alert-error";
$this->view->error = "修改失败,请重试";
$this->view->info = $data;
return true;
}
}else{
$this->view->info = $usr->getUserInfo($uid);
}
}
function AccountEditParamFilter(){
$data = array();
$data['realname'] = substr(trim($this->_getParam('realname')),0,40);
$data['unit'] = substr(trim($this->_getParam('unit')),0,100);
$data['address'] = substr(trim($this->_getParam('address')),0,100);
$data['phone'] = substr(trim($this->_getParam('phone')),0,15);
$data['postcode'] = substr(trim($this->_getParam('postcode')),0,15);
$data['project_type'] = substr(trim($this->_getParam('project_type')),0,100);
$data['project_id'] = substr(trim($this->_getParam('project_id')),0,40);
$data['project_title'] = substr(trim($this->_getParam('project_title')),0,100);
$data['project'] = substr(trim($this->_getParam('project')),0,600);
foreach($data as $k=>$v)
{
$data[$k] = $this->StringFilter($v);
}
return $data;
}
function StringFilter($string){
$string = preg_replace ('/<[^>]*>/', ' ', $string);
return $string;
}
function secureAction()
{
$this->view->pageID = "account-secure";
include_once("Users.php");
$usr = new Users($this->db);
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$uid = $user->id;
}
$opt = $this->_getParam('opt');
$submit = $this->_getParam('submit');
if(empty($opt))
{
$this->view->section = "password";
if(!empty($submit))
{
$data = $this->AccountSecureParamFilter();
$this->view->AlertType = "alert-error";
if(strlen($data['password'])>18 || strlen($data['new_password'])>18)
{
$this->view->error = view::Error("密码过长");
return true;
}
if(strlen($data['new_password'])<=6 || strlen($data['new_password_confrim'])<=6)
{
$this->view->error = view::Error("密码过短请输入大于6位的密码");
return true;
}
if(md5($data['new_password']) != md5($data['new_password_confrim']))
{
$this->view->error = view::Error("两次输入的密码不相同");
return true;
}
$sql = "SELECT password FROM users WHERE id=$uid";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(md5($data['password']) != $row['password'])
{
$this->view->error = view::Error("原密码不正确");
return true;
}
$data['password'] = md5($data['new_password']);
unset($data['new_password']);
unset($data['new_password_confrim']);
if($this->db->update("users",$data,"id=$uid"))
{
view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure'));
return true;
}else{
$this->view->error = view::Error("修改失败");
return true;
}
}else{
$this->view->info = $usr->getUserInfo($uid);
}
}//password
if($opt == "email")
{
$this->view->section = "email";
if(!empty($submit))
{
$email = $this->_getParam('email');
$password = $this->_getParam('password');
if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email))
{
$this->view->error = view::Error("错误的邮箱格式");
return true;
}
$sql = "SELECT password FROM users WHERE id=$uid";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(md5($password) != $row['password'])
{
$this->view->error = view::Error("原密码错误");
return true;
}
$data['email'] = $email;
if($this->db->update("users",$data,"id=$uid"))
{
view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure'));
return true;
}else{
$this->view->error = view::Error("修改失败");
return true;
}
}else{
$this->view->info = $usr->getUserInfo($uid);
}
}//email
}
function AccountSecureParamFilter(){
$data = array();
$data['password'] = trim($this->_getParam('password'));
$data['new_password'] = trim($this->_getParam('new_password'));
$data['new_password_confrim'] = trim($this->_getParam('new_password_confrim'));
foreach($data as $k=>$v)
{
$data[$k] = $this->StringFilter($v);
}
return $data;
}
}

View File

@ -1,82 +1,82 @@
<?php <?php
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('我的账户'); $this->headTitle('我的账户');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->theme->AppendPlus($this,'colorbox'); //$this->theme->AppendPlus($this,'colorbox');
?> ?>
<div class="row"> <div class="row">
<div class="span3"> <div class="span3">
<div class="well sidebar-nav"> <div class="well sidebar-nav">
<?= $this->partial('account/left.phtml'); ?> <?= $this->partial('account/left.phtml'); ?>
</div><!--/.well --> </div><!--/.well -->
</div><!--/span--> </div><!--/span-->
<div class="span9"> <div class="span9">
<h3>修改安全性设置</h3> <h3>修改安全性设置</h3>
<hr /> <hr />
<div class="tabbable"> <div class="tabbable">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li <?php if($this->section == "email" || empty($this->section)) echo 'class="active"'?>><a href="#tab2" data-toggle="tab">电子邮箱</a></li> <li <?php if($this->section == "email" || empty($this->section)) echo 'class="active"'?>><a href="#tab2" data-toggle="tab">电子邮箱</a></li>
<li <?php if($this->section == "password") echo 'class="active"'?>><a href="#tab3" data-toggle="tab">修改密码</a></li> <li <?php if($this->section == "password") echo 'class="active"'?>><a href="#tab3" data-toggle="tab">修改密码</a></li>
</ul> </ul>
<?php if(!empty($this->error)) { ?> <?php if(!empty($this->error)) { ?>
<?= $this->error ?> <?= $this->error ?>
<?php } ?> <?php } ?>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane <?php if($this->section == "email" || empty($this->section)) echo 'active'?>" id="tab2"> <div class="tab-pane <?php if($this->section == "email" || empty($this->section)) echo 'active'?>" id="tab2">
<div id="email"> <div id="email">
<form id="opt_email" action="/account/secure/opt/email" method="post" class="form-horizontal"> <form id="opt_email" action="/account/secure/opt/email" method="post" class="form-horizontal">
<div class="control-group"> <div class="control-group">
<label class="control-label">Email:</label> <label class="control-label">Email:</label>
<div class="controls"> <div class="controls">
<input type="text" value="" name="email" /> <input type="text" value="" name="email" />
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label">密码:</label> <label class="control-label">密码:</label>
<div class="controls"> <div class="controls">
<input type="password" name="password" /> <input type="password" name="password" />
<span class="help-inline">如果要修改邮箱,请输入原密码</span> <span class="help-inline">如果要修改邮箱,请输入原密码</span>
</div> </div>
</div> </div>
<div class="form-actions"> <div class="form-actions">
<input type="hidden" name="submit" value="submit" /> <input type="hidden" name="submit" value="submit" />
<button type="submit" class="btn btn-green" class="btn btn-primary">保存</button> <button type="submit" class="btn btn-green" class="btn btn-primary">保存</button>
<button type="reset" id="reset" class="btn">取消</button> <button type="reset" id="reset" class="btn">取消</button>
</div> </div>
</form> </form>
</div> </div>
</div><!-- tab2 --> </div><!-- tab2 -->
<div class="tab-pane <?php if($this->section == "password") echo 'active'?>" id="tab3"> <div class="tab-pane <?php if($this->section == "password") echo 'active'?>" id="tab3">
<div id="password"> <div id="password">
<form action="/account/secure" method="post" class="form-horizontal"> <form action="/account/secure" method="post" class="form-horizontal">
<div class="control-group "> <div class="control-group ">
<label class="control-label">当前密码</label> <label class="control-label">当前密码</label>
<div class="controls"> <div class="controls">
<input name="password" type="password" value="" /> <input name="password" type="password" value="" />
<span class="help-inline">如果要修改密码,请输入原密码</span> <span class="help-inline">如果要修改密码,请输入原密码</span>
</div> </div>
</div> </div>
<div class="control-group "> <div class="control-group ">
<label class="control-label">新密码</label> <label class="control-label">新密码</label>
<div class="controls"> <div class="controls">
<input type="password" name="new_password" value="" /> <input type="password" name="new_password" value="" />
</div> </div>
</div> </div>
<div class="control-group "> <div class="control-group ">
<label class="control-label">确认新密码</label> <label class="control-label">确认新密码</label>
<div class="controls"> <div class="controls">
<input type="password" name="new_password_confrim" value="" /> <input type="password" name="new_password_confrim" value="" />
</div> </div>
</div> </div>
<div class="form-actions"> <div class="form-actions">
<input type="hidden" name="submit" value="submit" /> <input type="hidden" name="submit" value="submit" />
<button type="submit" class="btn btn-primary">确定</button> <button type="submit" class="btn btn-primary">确定</button>
<button type="button" class="btn">取消</button> <button type="button" class="btn">取消</button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div><!--/span--> </div><!--/span-->
</div> </div>
</div> </div>
</div><!--/row--> </div><!--/row-->