Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Is there any way to use a Middleware that will intercept every request?

jenisjenis New
edited July 2018 in Vanilla 2.0 - 2.8

First of all, thanks for such a great forum.

We are using it and creating our custom application (addon) so wondering, is there any middleware available where we can perform our permission checks or any logic before passing control to controllers?

Comments

  • R_JR_J Admin

    Is your custom addon a Vanilla addon? Then it is quite easy. You can use the events in the dispatcher for this. Look at /library/core/class.dispatcher.php for detailed information. You can use it like that in your adddon:

    public function gdn_dispatcher_beforeDispatch_handler($sender, $args) {
        $request = $args['Request']; // See class.request.php for what you can do with that
    
        if ($this->checkbackWithGandalf($request->path(), Gdn::session()->User) !== true) {
            throw new Exception('Sorry, but Gandalf says you shall not pass...', 403);
        }
        // All good
        ...
    }
    
  • Okay thanks, will try it out.

Sign In or Register to comment.