Drupal Auto Assign Role Module: Control your Drupal roles
Share with Others
The Drupal 7 Auto Assign Role module allows you a lot of flexibility in deciding what roles users receive on your Drupal 7 website. If you have ever needed to allow a user to select their own role, or if you have ever needed to automatically assign a role to every user on your Drupal site. This is the module for you.
There are three options for configuring the auto assign role module. One is to always automatically assign a specific role to every user that signs up for your site. The second option is to allow a user to select one or more roles on the user registration page when they are signing up for their user account. The last option is to have separate registration pages for each role. This one allows you to really design the user registration process to a specific workflow.
This module can be very useful on social networking sites, forum or discussion board sites, some types of ecommerce sites (where you might want to allow users to sign up as sellers), and much more. This module is useful anytime you want a user to be able to categorize themselves into a specific role, and you want those roles to have different permissions across your site.
Hello everyone and welcome to another Daily Dose of Drupal. Today we’re on Episode Number 190 and we’re going to be covering the Auto Assign Role Module. But before we get started I am Shane Thomas, make sure to follow me on Twitter at smthomas3. Also make sure to head on over to codekarate.com, check out the EBook and all the other useful Drupal information.
So let’s go ahead and get started; The Auto Assign Role Module, it’s a really simple module but it does some pretty powerful things. It allows you to really control how users get roles on your Drupal site. So there are options to allow you to Auto Assign a role anytime a user assigns up for your site but you can also set it so the user can select their own role. And this is very powerful if you’re building out a site where…depending on what kind of user you want to have or what type of users you have coming to your site.
You may want to give them different permissions for…and since if you’re building an education site, you might want a teacher and a student role and the user would select that one they sign up. In this case we’ll go through one example with a reviewer or a manager role just as simple example since I already have those roles on this test site.
So make sure to go over to your test site and turn on the Auto Assign Role Module. Once that is installed we are going to go ahead and go to the configuration page and there are three options here and we’ll go through each of these. The first one is automatic.
So if we click on that you can see we can enable automatic role assignment which essentially means if any user creates a new account on your site they will be automatically whatever roles you check down here. Otherwise you can also turn on Automatic Role Assignment for Admin created accounts and this means any role that you would create as an admin would get or any user would get the role that you select down here. So if you want to make sure that either all admin accounts are all user created accounts end up getting a specific role, this module can be used to do that.
I’m not going to go through a demo on that because it’s pretty straight forward. The per role pages, we’ll go through that one last and we’ll start or we’ll go second with the User Choice. This one is pretty cool because you can actually allow the user to select their role on the user registration form. So the first thing we have to do is enable it. So we change this to Enabled and then we select the roles that they should be able to select from.
We don’t want to allow them to become an administrator of course but we will allow them to select either a manager or a reviewer role and this will just show any roles that you have on your site. So if you need to change your roles you can always go to people permissions and then roles. You can select if they should be able to select one or more than one role when signing up.
We’ll just keep it with one and then if you want radio buttons or select box, if you want it to be required I’ll go ahead and say yes, how do you want to sort it, what kind of description and what title do you want to show up. Let’s go ahead and hit Save and I will open up a new window here and we will go to the site and click on the Create New Account button. You’ll now see there’s a role selection here where I can select either Manager or Reviewer. You can see the description shows up there, the field set title and the actual field title.
I’ll go ahead and sign up for one here and I will select to be a manager and click Create New Account. Now I don’t have the ability for users to be able to create and sign into their own accounts. It’s still set up to require admin approval but this works regardless of how you have that set up on your Drupal site. So if I come back here and go to the people page you’ll see there’s a test role user I just created. It is blocked because I have to manually approve them but it does have the role of manager.
So that’s an easy way to allow on your user registration form a user to just select the role they want. The other option is to configure per role pages and this basically means you can create different paths or different sign-up forms and depending on the sign-up form that they go to is the roles or the role that they will receive.
So we’re going to create one for the manager role and we give it a title. We give it a path so we’re going to give it manager-signup. You can add it to a menu if you want if you want to actually to display in a menu item and you can select the display type. If you select standard it will show the normal user registration, user login, requesting your password, Drupal tabs, if you show it individually it will not show those tabs. I’ll leave this one at standard and I’ll change the other one to individual so we can see what the difference is there. So here’s the manager signup, so let’s also add a Reviewer signup page, so we give it a title and a path, we’re going to select individual this time and go ahead and click Add.
Now if we come back to the site you’ll notice we still have these options so we could turn that off if we wanted to but if I go to manager-signup you can see it’s the manager signup title which means if I sign up for this form I’m going to become a manager and receive the manager role. And also notice how the tabs are showing up here.
If I go to reviewer-signup there are no tabs. There we go, so I just created a quick reviewer account on that reviewer signup page so we can ensure that I would get the reviewer role. So if we come back to the people page and refresh you’ll notice here’s my username, here’s the role I would have receive and there we go. That’s the Auto Assign Role Module. So as you can see it allows a lot of flexibility with controlling how roles are assigned throughout your Drupal site.
So this is incredibly useful if you’re building out as I mentioned before, some kind of social network site or education site where there are different roles and different permissions that need to be applied to those different users. So go ahead and give that one a try, make sure to check out codekarate.com and let us know if you want anything that we don’t already have up there and we’ll see you next time. Thanks for watching.