westdc-zf1/application/default/controllers/AccountController.php

276 lines
6.6 KiB
PHP
Executable File

<?php
use Helpers\View as view;
use Users\Account;
use Users\Gravatar;
class AccountController extends Zend_Controller_Action
{
private $memberTable = "tbl_member";
private $FieldUsername = "username";
private $FieldPasword = "password";
private $FieldLastlogin = "ts_last_login";
private $FieldEmail = "email";
private $FieldLastloginIp = "last_login_ip";
function preDispatch()
{
$this->view->config = Zend_Registry::get('config');
$this->_request->setParam('return', $this->_request->getServer('REQUEST_URI'));
$this->db=Zend_Registry::get('db');
$this->view->Theme = new Theme();
}
function indexAction()
{
$submit = $this->_getParam('submit');
$account = new Account();
if(!empty($submit))
{
$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)
{
$this->view->error = view::Error($status);
}else{
$this->view->error = view::Error("修改成功","alert-success");
}
}
$user = $account->getAccountInfo();
$av = new Gravatar();
$this->view->avatar = $av->Get($user['email'],100);
$this->view->user = $user;
}
function loginAction()
{
$request = new \Zend_Controller_Request_Http();
if($request->isXmlHttpRequest())
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = $this->_getParam('data');
if(empty($data))
{
$this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
}
$data = \Helpers\MCrypt::decrypt($data,"DY7567");
$data = json_decode($data,true);
$account = new Account();
$result = $account->login($data,true);
if(!empty($result))
{
$content = json_encode($result,JSON_NUMERIC_CHECK);
echo \Helpers\MCrypt::encrypt($content,"CH6668");
return true;
}
$this->jsonexit(array('error'=>'服务器掉链子了,请重试'));
return true;
}
$success=false;
$options = array(
'module' => $this->_request->getModuleName(),
'controller' => $this->_request->getControllerName(),
'action' => $this->_request->getActionName(),
);
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity())
{
if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")
{
$this->_redirect("/");
}else{
$this->_redirect($_SERVER['REQUEST_URI']);
}
}
$tohref = $this->_request->getParam('href');
if($_SERVER['REQUEST_URI'] !== "/account/login")
{
$this->view->href = $_SERVER['REQUEST_URI'];
}else{
$this->view->href = "/";
}
if(!empty($tohref))
{
$this->view->href = $tohref;
}
$submit = $this->_getParam("submit");
if(!empty($submit))
{
$data = array(
'username' => $this->_getParam('username'),
'password' => $this->_getParam('password')
);
$account = new Account();
$result = $account->login($data);
if(!empty($result))
{
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 = "处理中出现问题";
return true;
}
}
}//登陆
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();
$account = new Account();
$data = $account->getParam($this->_request);
$result = $account->register($data);
if(!empty($result))
{
$this->jsonexit($result);
return true;
}
$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))
{
if(isset($result['error']))
{
$this->view->place = $result['place'];
$this->view->error = $result['error'];
return true;
}
if(isset($result['success']))
{
$this->_redirect('/');
return true;
}
}else{
$this->view->error = "处理中出现问题";
return true;
}
}
}//用户注册
//退出登录
function logoutAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity())
{
$auth->clearIdentity();
Users\Member::flushcookie();
$this->_redirect('/');
}
}
//找回密码
function forgotpasswordAction()
{
$this->_helper->layout->disableLayout();
$submit = $this->_getParam('submit');
if(!empty($submit))
{
$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 = "申请成功!请在您的邮箱中查看密码重置邮件";
}
}
}
//重置密码
function getpasswordAction()
{
$this->_helper->layout->disableLayout();
$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']))
{
$this->view->error = $status['error'];
}else{
$this->view->msg = "您的密码已经成功更改,<a href='/account/login'>请点击这里登陆</a>";
}
}
}//getpasswordAction()
}