Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

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 Cheerleader & Troubleshooter Munich Moderator

    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
        ...
    }
    


    Bleistivt
  • Okay thanks, will try it out.

Sign In or Register to comment.