Sinmok Posted October 7, 2014 Share Posted October 7, 2014 Hello all, Need a bit of advice. I have a page structure where users with a specific role either can or can't view the page. The problem is, is that I need to be able to have users who can add other users..but only assign them to specific roles. For example: A manager can add users and assign the roles: Supervisor or worker A supervisor can add users but only assign the new users with the role of worker A worker can't add any users. Is this currently possible to do in processwire? If not, how would you go about doing it? Link to comment Share on other sites More sharing options...
davo Posted October 7, 2014 Share Posted October 7, 2014 Depends where you want to start with this really. The very simplest way would be to use Ryan's form builder module. This form could be made available only to each of your two types of users that can create other users. The form builder can publish straight to pages. Users are also just pages. Just make two identical forms, one for managers and one for supervisors; the only difference being one has extra options in the role drop down. Just make sure your fields match the 'user' page fields. Or, it's fairly simple to make your own user registration page. Create a form in html. Post the form back to the same template and process it. You'll find $user->hasRole($role) useful. Here's a simple example from the docs: <?php $u = new User(); $u->name = "gonzo"; $u->pass = "BamBam!"; $u->addRole("guest"); // substitute this for your worker, manager or supervisor role $u->save(); Both are pretty simple. Personally, I'd start with the do it yourself method so you understand how pw works better. You'll find lot's of help if you have a go. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted October 7, 2014 Share Posted October 7, 2014 The first question to ask would be, if you want this to happen in the processwire admin backend or via a selfwritten frontend form on your site. The latter is explained by davo, while the first one would need a different approach. Initially the backend only offers a "user-admin" permission, which grants full user editing permission. You would need to enhance the permission management via a small hooking module to get your restrictions working there. Link to comment Share on other sites More sharing options...
Sinmok Posted October 7, 2014 Author Share Posted October 7, 2014 Yeah, ideally this would all happen in the Processwire admin area. Small module that checks roles sounds like the best approach, I'm guessing I just need to hook into Page::save and check if the template is a user, and if so, what their roles are. 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