XF 2.0 Bypass ban message during an XHR request?

Scandal

Well-known member
Well, if an acccount is banned and I'm trying to make an ajax request to a controller via that account, I get the ban message as return data, instead of the data, the controller trying to give as output.
With some research on the XF2 core, I found that the "stop" message is applied via the class \XF\Pub\Controller\AbstractContoller and method:
PHP:
    public function assertNotBanned()
    {
        if (\XF::visitor()->is_banned)
        {
            throw $this->exception(
                $this->plugin('XF:Error')->actionBanned()
            );
        }
    }

Is there a way to bypass that method / or prevent it from applying the stop message, for example, if the $ajaxaction has a specific value?
PHP:
$ajaxaction = $this->filter('act', 'str');

Maybe with a Listener? I'm not 100% sure how to apply it. :)
 
Well, if your criteria can be manipulated from the client side, why not just simply disable the ban check?
You could probably set permissions for whatever you are trying to do, though. Just give the banned group some rights.
 
Hello yoloswaggerino! Nice idea, will take a look on XF2 settings. :)

But my my main question is remaining about the development side: how could I make a method of a class to return something else than its default?
I just need to understand how to replace a functionality. Maybe by adding a Code Event Listener? I'm a bit new to the object-oriented side of PHP. As anyone I'm trying to understand how the XF2 works for developers. :)
 
You should extend the controller that is receiving your ajax request and override the assertNotBanned() function to not run when the conditions you're looking for are met.
 
Well, I extended some XF classes with success for the addon I'm working, but, about the XF\Pub\Controller\AbstractController it seems that it is not working. I have done exact the same steps like the other class extensions which working, but for this it is not work.
Below I describe what exact I'm doing.

1. Create a file src/addons/Scandals/Dev/XF/Pub/Controller/My.php with this content:
PHP:
namespace Scandals\Dev\XF\Pub\Controller;
use XF\Pub\Controller\AbstractController;

class My extends AbstractController
{
    public function assertNotBanned()
    {
        return true;
       
        // otherwise return the main class "reply" to this check
        $main_reply = parent::assertNotBanned();
        return $main_reply;
    }
}
2. Then I create the class extension on admin control panel:
Base class name: XF\Pub\Controller\AbstractController
Extension class name: Scandals\Dev\XF\Pub\Controller\My

But for some reason. my own method assertNotBanned() is not override the parent's class method. Any idea?

Finally, to notice that I tried also instead of "My" to write "AbstractController" and also instead of "AbstractController" to write "XFCP_AbstractController".

Does the AbstractController has something special as class? :)
 
Yes, of course. :)
I apply return true; to see if it will work, but it is not working. If I apply hardcoded the return true; to main class's method, it will work. But here we're talking about class extension so it is not an accept solution the file modifications on main XF2 core. (y)
 
Pretty sure abstract classes are never called directly, so you will have to extend the actual class which originally extended the controller. That's what @JulianD suggested aswell. You can hook into that then. Like probably every controller in /src/XF/Pub/Controller/ and /src/XF/Admin/Controller/. You will need to extend one of those.
 
Back
Top Bottom