2011-12-28 06:37:46 +00:00
|
|
|
<?php
|
2013-12-13 08:42:34 +00:00
|
|
|
use Helpers\View as view;
|
|
|
|
use Users\Account;
|
|
|
|
use Users\Gravatar;
|
|
|
|
|
2011-12-28 06:37:46 +00:00
|
|
|
class AccountController extends Zend_Controller_Action
|
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
private $memberTable = "tbl_member";
|
|
|
|
private $FieldUsername = "username";
|
|
|
|
private $FieldPasword = "password";
|
|
|
|
private $FieldLastlogin = "ts_last_login";
|
|
|
|
private $FieldEmail = "email";
|
|
|
|
private $FieldLastloginIp = "last_login_ip";
|
|
|
|
|
2013-03-15 04:16:07 +00:00
|
|
|
function preDispatch()
|
|
|
|
{
|
|
|
|
$this->view->config = Zend_Registry::get('config');
|
|
|
|
$this->_request->setParam('return', $this->_request->getServer('REQUEST_URI'));
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->db=Zend_Registry::get('db');
|
|
|
|
$this->view->Theme = new Theme();
|
2013-03-15 04:16:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 06:37:46 +00:00
|
|
|
function indexAction()
|
|
|
|
{
|
2013-03-15 04:16:07 +00:00
|
|
|
$submit = $this->_getParam('submit');
|
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
$account = new Account();
|
|
|
|
|
2013-03-15 04:16:07 +00:00
|
|
|
if(!empty($submit))
|
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$data = $account->getEditParam($this->_request);
|
|
|
|
$Listener = new EditListener();
|
|
|
|
@$account->events()->attachAggregate($Listener);
|
|
|
|
$this->view->section = $type = $this->_getParam('type');
|
|
|
|
$status = $account->edit($data,$type);
|
|
|
|
if($status !== true)
|
2013-03-15 04:16:07 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->view->error = view::Error($status);
|
2013-03-15 04:16:07 +00:00
|
|
|
}else{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->view->error = view::Error("修改成功","alert-success");
|
2013-03-15 04:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
$user = $account->getAccountInfo();
|
|
|
|
$av = new Gravatar();
|
|
|
|
$this->view->avatar = $av->Get($user['email'],100);
|
|
|
|
$this->view->user = $user;
|
|
|
|
}
|
2013-03-15 04:16:07 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
function loginAction()
|
|
|
|
{
|
|
|
|
$request = new \Zend_Controller_Request_Http();
|
|
|
|
if($request->isXmlHttpRequest())
|
2013-03-15 04:16:07 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
|
|
|
|
$data = $this->_getParam('data');
|
|
|
|
if(empty($data))
|
2013-03-15 04:16:07 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
|
2013-03-15 04:16:07 +00:00
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
|
|
|
|
$data = \Helpers\MCrypt::decrypt($data,"DY7567");
|
|
|
|
$data = json_decode($data,true);
|
|
|
|
|
|
|
|
$account = new Account();
|
|
|
|
$result = $account->login($data,true);
|
|
|
|
|
|
|
|
if(!empty($result))
|
2013-03-15 04:16:07 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$content = json_encode($result,JSON_NUMERIC_CHECK);
|
|
|
|
echo \Helpers\MCrypt::encrypt($content,"CH6668");
|
|
|
|
return true;
|
2013-03-15 04:16:07 +00:00
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
|
|
|
|
$this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
|
|
|
|
|
|
|
|
return true;
|
2013-03-15 04:16:07 +00:00
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
|
|
|
|
$success=false;
|
2013-06-20 08:59:32 +00:00
|
|
|
|
|
|
|
$options = array(
|
|
|
|
'module' => $this->_request->getModuleName(),
|
|
|
|
'controller' => $this->_request->getControllerName(),
|
|
|
|
'action' => $this->_request->getActionName(),
|
|
|
|
);
|
2013-12-13 08:42:34 +00:00
|
|
|
|
2011-12-28 06:37:46 +00:00
|
|
|
$auth = Zend_Auth::getInstance();
|
2013-06-20 08:59:32 +00:00
|
|
|
if ($auth->hasIdentity())
|
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")
|
|
|
|
{
|
|
|
|
$this->_redirect("/");
|
|
|
|
}else{
|
|
|
|
$this->_redirect($_SERVER['REQUEST_URI']);
|
|
|
|
}
|
2013-06-20 08:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$tohref = $this->_request->getParam('href');
|
|
|
|
|
2013-12-26 07:59:00 +00:00
|
|
|
if($_SERVER['REQUEST_URI'] !== "/account/login")
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-09-30 02:00:43 +00:00
|
|
|
$this->view->href = $_SERVER['REQUEST_URI'];
|
2013-12-26 07:59:00 +00:00
|
|
|
}else{
|
|
|
|
$this->view->href = "/";
|
2013-09-30 02:00:43 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 08:59:32 +00:00
|
|
|
if(!empty($tohref))
|
|
|
|
{
|
|
|
|
$this->view->href = $tohref;
|
|
|
|
}
|
|
|
|
|
|
|
|
$submit = $this->_getParam("submit");
|
2013-12-13 08:42:34 +00:00
|
|
|
|
2013-06-20 08:59:32 +00:00
|
|
|
if(!empty($submit))
|
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$data = array(
|
|
|
|
'username' => $this->_getParam('username'),
|
|
|
|
'password' => $this->_getParam('password')
|
|
|
|
);
|
2013-06-20 08:59:32 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
$account = new Account();
|
|
|
|
$result = $account->login($data);
|
2012-07-06 03:30:59 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
if(!empty($result))
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
if(isset($result['error']))
|
|
|
|
{
|
|
|
|
$this->view->error = $result['error'];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(isset($result['success']))
|
|
|
|
{
|
|
|
|
$this->_redirect($this->view->href);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$this->view->error = "处理中出现问题";
|
2013-06-20 08:59:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
}
|
|
|
|
}//登陆
|
|
|
|
|
|
|
|
public function jsonexit($data){
|
|
|
|
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerAction()
|
|
|
|
{
|
|
|
|
$request = new \Zend_Controller_Request_Http();
|
|
|
|
if($request->isXmlHttpRequest())
|
|
|
|
{
|
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
2013-06-20 08:59:32 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
$account = new Account();
|
|
|
|
$data = $account->getParam($this->_request);
|
2013-06-20 08:59:32 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
$result = $account->register($data);
|
2013-06-20 08:59:32 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
if(!empty($result))
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->jsonexit($result);
|
2013-06-20 08:59:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
|
|
|
|
$this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试'));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
//$this->_helper->layout->disableLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$success=false;
|
|
|
|
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
if ($auth->hasIdentity())
|
|
|
|
$this->_redirect('/');
|
|
|
|
|
|
|
|
$submit = $this->_getParam('submit');
|
|
|
|
if(!empty($submit))
|
|
|
|
{
|
|
|
|
$account = new Account();
|
|
|
|
$this->view->data = $data = $account->getParam($this->_request);
|
|
|
|
$result = $account->register($data);
|
|
|
|
|
|
|
|
if(!empty($result))
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
if(isset($result['error']))
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->view->place = $result['place'];
|
|
|
|
$this->view->error = $result['error'];
|
2013-06-20 08:59:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
if(isset($result['success']))
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->_redirect('/');
|
2013-06-20 08:59:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
}else{
|
|
|
|
$this->view->error = "处理中出现问题";
|
|
|
|
return true;
|
2013-06-20 08:59:32 +00:00
|
|
|
}
|
2011-12-28 06:37:46 +00:00
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
}//用户注册
|
|
|
|
|
|
|
|
//退出登录
|
|
|
|
function logoutAction()
|
|
|
|
{
|
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
|
|
|
|
$auth = Zend_Auth::getInstance();
|
2013-06-20 08:59:32 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
if ($auth->hasIdentity())
|
|
|
|
{
|
|
|
|
$auth->clearIdentity();
|
|
|
|
Users\Member::flushcookie();
|
|
|
|
$this->_redirect('/');
|
|
|
|
}
|
2011-12-28 06:37:46 +00:00
|
|
|
}
|
2013-06-20 08:59:32 +00:00
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
//找回密码
|
|
|
|
function forgotpasswordAction()
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
|
|
|
|
$submit = $this->_getParam('submit');
|
|
|
|
|
|
|
|
if(!empty($submit))
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$email = $this->_getParam('email');
|
|
|
|
$account = new Account();
|
|
|
|
$status = $account->getMyPassword($email);
|
|
|
|
if(isset($status['error']) && !empty($status['error']))
|
|
|
|
{
|
|
|
|
$this->view->error = $status['error'];
|
|
|
|
}else{
|
|
|
|
$this->view->msg = "申请成功!请在您的邮箱中查看密码重置邮件";
|
|
|
|
}
|
2013-06-20 08:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
//重置密码
|
|
|
|
function getpasswordAction()
|
2013-06-20 08:59:32 +00:00
|
|
|
{
|
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
|
2013-12-13 08:42:34 +00:00
|
|
|
$submit = $this->_getParam('submit');
|
|
|
|
|
|
|
|
if(!empty($submit))
|
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
'username' => $this->_getParam('username'),
|
|
|
|
'password' => $this->_getParam('password'),
|
|
|
|
'confirm_password' => $this->_getParam('confirm_password'),
|
|
|
|
'salt' => $this->_getParam('salt')
|
|
|
|
);
|
|
|
|
$account = new Account();
|
|
|
|
$status = $account->resetPassword($data);
|
|
|
|
if(isset($status['error']) && !empty($status['error']))
|
2011-12-28 06:37:46 +00:00
|
|
|
{
|
2013-12-13 08:42:34 +00:00
|
|
|
$this->view->error = $status['error'];
|
|
|
|
}else{
|
|
|
|
$this->view->msg = "您的密码已经成功更改,<a href='/account/login'>请点击这里登陆</a>";
|
2011-12-28 06:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-13 08:42:34 +00:00
|
|
|
}//getpasswordAction()
|
2013-09-30 02:00:43 +00:00
|
|
|
|
2011-12-28 06:37:46 +00:00
|
|
|
}
|
|
|
|
|