Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...