Jump to content

Restricting access to pages


BeardedCanadian
 Share

Recommended Posts

So I have been slowly working on migrating content from my old site to my new PW site. One of the things that I would really like to impliment is a way of restricting access to some content. In particular, I have certain family content (i.e. kids photos, videos, etc) that are really only for friends/family. Can someone outline the best way of accomplishing this? I'm still a n00b at PW. I've found this thread which describes how to restrict content for a whole site and I'm already using this module to restrict access to some pages to my local network.  Ideally, I'd like a graceful fallback so if an unauthorized person tries to view content so they would be given a polite message and a login prompt.

I'd be grateful if someone could walk me through what the best approach to accomplishing this. Thanks everyone!

Link to comment
Share on other sites

Lets say you've got the page /family/ that has everything below it you want protected by a login. 

  • Create a new role (in Access > Roles), call it whatever you'd like but maybe "family" is a good name. For permissions, check the box for Page View, and that's it. Create one or more new users for your family, and give them the family role. 
  • In your admin edit the template used by your /family/ page (let's say it's also called 'family') and go to the 'Access' tab. Check the box to enable access control. For view access, check the box for "family" but not for "guest".
  • Also when editing your family template, for the section on "what to do when a user doesn't have access", choose the box to redirect them to the login form. Or if you want your own custom login form, you can later change this to redirect to a custom URL that contains your login form. 
  • In your /site/config.php file, see the section on the "pagefileSecure" option and determine if that is something you will want to use or not. By default is is off. 
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

This is just what I was looking for! But, is it possible to have one the pages under the protected section be available for guests view/access? 

Parent [template=parent] > No guest access [lock icon]

--- Child 1 [template=child] > No guest access

--- Child 2 [template=child] > Guest access [unlock icon] 

--- Child 3 [template=child] > No guest access

I see this is not a common behaviour to replicate in the admin, and may need some template coding instead. My first idea was to give the child template no restrictions, and then in the child.php template, do some access checking. This way the parent is protected, but each children can be set to public via a checkbox in the page edit screen. This could work, right?

The only caveat is that I would like to keep the lock icon coding after the page name in the tree. This is, I would like to keep the unlock icon next to the pages with guest access. Maybe there's a hook available for this in the admin?

Any help will be appreciated!!!

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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