Skip to content

Commit

Permalink
bugfix error control bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xw2423 committed Mar 3, 2014
1 parent 45435f3 commit 993515f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
2 changes: 2 additions & 0 deletions app/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public function _initRoute($dispatcher){

public function _initPlugin($dispatcher){
$tmp = c('plugins.install');
if(null !== c('modules.install.1'))
array_splice($tmp, 0, 0, 'module');
$tmp[] = 'redirect';
foreach($tmp as $k=>&$v){
if(trim($v) === '') continue;
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public function errorAction($exception = null) {
));
$this->render('error');
}else if(is_a($exception, 'NF_ERROR404Exception')
|| is_a($exception, 'Yaf_Exception')){
|| is_a($exception, 'Yaf_Exception')
|| !is_a($exception, 'Exception')){
header('HTTP/1.1 404 Not Found');
$this->set('siteName', c('site.name'));
$this->render('error404');
Expand Down
2 changes: 1 addition & 1 deletion app/modules/Api/controllers/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public function errorAction($exception = null) {
$msg = ECode::msg($code);
}else if(is_a($exception, 'NF_ERROR404Exception')
|| is_a($exception, 'Yaf_Exception')
|| null === $exception){
|| !is_a($exception, 'Exception')){
$code = ECode::$SYS_404;
$msg = ECode::msg($code);
}else{
Expand Down
8 changes: 6 additions & 2 deletions app/modules/Api/lib/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class NF_ApiController extends NF_Controller {

public function init(){
c('application.encoding', 'utf-8');
$this->cache(false);
parent::init();
$this->getRequest()->front = true;
$this->_abase = c('modules.api.base');

if($this->getRequest()->ext === 'html'
&& !($this->getRequest()->getControllerName() === 'Attachment' && $this->getRequest()->getActionName() === 'download'))
exit('Unknow Return Format');
$this->cache(false);
load('inc/wrapper');
}

Expand All @@ -32,6 +32,10 @@ protected function afterRender(){}

protected function _initSession(){
load('api.session');
NF_ApiSession::getInstance()->init();
try{
NF_ApiSession::getInstance()->init();
}catch(LoginException $e){
$this->error($e->getMessage());
}
}
}
2 changes: 1 addition & 1 deletion app/plugins/Ipacl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstr
load(CONF . DS . 'ipacl', $acl);

if(!self::check($acl['global']))
exit(Ecode::msg(ECode::$SYS_IPBAN));
nforum_error(ECode::$SYS_IPBAN, $request->front);

$m = strtolower($request->getModuleName());
$c = strtolower($request->getControllerName());
Expand Down
18 changes: 18 additions & 0 deletions app/plugins/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Module plugin for nforum
*
* @author xw
*/
class ModulePlugin extends Yaf_Plugin_Abstract{
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response){
if('Index' !== ($m = $request->getModuleName())){
//if use domain, Index can't visit
$d = c('modules.' . strtolower($m) . '.domain');
if(!empty($d) && c('site.domain') != 'http://' . $d)
nforum_error404(true);

load(MODULE . DS . $request->getModuleName() . DS . 'lib' . DS . 'controller.php');
}
}
}
17 changes: 5 additions & 12 deletions app/plugins/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
class RedirectPlugin extends Yaf_Plugin_Abstract{

public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response){
if('Index' !== ($m = $request->getModuleName())){
//if use domain, Index can't visit
$d = c('modules.' . strtolower($m) . '.domain');
if(!empty($d) && c('site.domain') != 'http://' . $d)
nforum_error404(true);

load(MODULE . DS . $request->getModuleName() . DS . 'lib' . DS . 'controller.php');
if('Mobile' === $m || 'Api' === $m){
if($request->isXmlHttpRequest())
nforum_error404(true);
else
return;
}
if('Mobile' === $request->getModuleName() || 'Api' === $request->getModuleName()){
if($request->isXmlHttpRequest())
nforum_error404(true);
else
return;
}

//check ajax_* action via xhr in header
Expand Down
22 changes: 12 additions & 10 deletions lib/inc/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ public function redirect($url, $status = null, $exit = true){
nforum_redirect($this->base . $url);
}

public function error($mixed = null){
nforum_error($mixed);
public function error($mixed = null, $simple = false){
if('Error' !== $this->getRequest()->controller)
nforum_error($mixed, $simple);
}

public function error404(){
nforum_error404();
public function error404($blank = false){
if('Error' !== $this->getRequest()->controller)
nforum_error404($blank);
}

/**
Expand Down Expand Up @@ -378,16 +380,16 @@ protected function _initKbs(){
load(array('model/forum', 'model/user'));

//init session
try{
$this->_initSession();
}catch(LoginException $e){
nforum_error($e->getMessage(), true);
}
$this->_initSession();
$this->_initKbs = true;
}

protected function _initSession(){
load('model/session');
NF_Session::getInstance()->init($this->getRequest()->get('sid', null));
try{
NF_Session::getInstance()->init($this->getRequest()->get('sid', null));
}catch(LoginException $e){
$this->error($e->getMessage(), true);
}
}
}

0 comments on commit 993515f

Please sign in to comment.