clemens Posted August 26, 2020 Share Posted August 26, 2020 Hi, I'm using pagefileSecure to protect a template (and specifically its files) from public access. Now I want to allow specific users to view their own files. I already tried hooking Page::viewable, but the template of the page (where the file is stored) doesn't even show up when I dump every hook. I have this code in site/ready.php $wire->addHook('Page::viewable', function (\ProcessWire\HookEvent $event) { bd($event->object->template->name); //my-template doesn't even show up here switch ($event->object->template->name) { case "my-template": $event->return = true; // the user still gets a 404 when attempting to access the file on frontend. break; default: break; } }); What would be the best way to allow access to specific files for individual users, even when they don't have a role that can view the page? Link to comment Share on other sites More sharing options...
Zeka Posted August 26, 2020 Share Posted August 26, 2020 @clemens Try to $wire->addHookAfter(); https://processwire.com/docs/modules/hooks/#do-i-want-my-hook-to-run-before-or-after-the-method-i-am-hooking-or-does-it-matter Link to comment Share on other sites More sharing options...
clemens Posted August 27, 2020 Author Share Posted August 27, 2020 That doesn't seem to change anything. The main issue imo is the fact that the page template in question doesn't even show when I dump every successful hook. I'm mostly surprised that I can't find any previous solutions to this issue. Link to comment Share on other sites More sharing options...
clemens Posted August 28, 2020 Author Share Posted August 28, 2020 Update: I managed to circumvent the whole thing by using wireSendFile() to serve the file for the specific user (via a different url, of course). I'm still very much interested in how to hook ::viewable when serving a file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now