Jump to content

Noob question about users


Marty Walker
 Share

Recommended Posts

Hi everyone,

I'm working on a site that gives users access to parts of the site. It goes something like this:

- Your Pages

-- Seminar 1

--- seminar page 1

--- seminar page 2

-- Seminar 2

--- seminar page 1

--- seminar page 2

 
... and so on
 
On the Seminar 1 & Seminar 2 pages I have a field called 'Allowed users' which is a Page field that looks at the admin/access/users page. I have it setup to display all the users as checkboxes.
 
I thought that I might have built an easy way for the admin to add selected users to each Seminar but I'm having trouble.
 
What I'm trying to do is match the logged in user with the checked username on the Seminar 1 & Seminar 2 pages and a) only show that user the seminars they have access to and b) all the pages below that belong to that seminar.
 
They're going to have quite a few seminars. Getting them to setup a Role for each seminar and then adding that role to each user would be quite tedious.
 
I haven't done much with user management at all in PW. Any ideas on how I might approach this? Is there a better way?
 
Regards
Marty
Link to comment
Share on other sites

Hi Marty,

What trouble do you have?

Let's say Seminar1 and Seminar2 both have the same template. If a user visits those sites, you should be able to do a check like this:

// Check if the current user can access this seminar page
if ($page->allowedUsers->has($user)) {
  // Good! List the Seminar children
} else {
  throw new Wire404Exception();
}

... where allowedUsers is your Page field (checkboxes) for the users. Of course you'd need also to check on the seminar subpages, so that a user can't access them directly:

if ($page->parent->allowedUsers->has($user)) {
  // Good!
} else {
  throw new Wire404Exception();
}
  • Like 6
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...