Drupal 7 Masquerade Module
If you are working on a Drupal website and need to switch users, you probably log out and log in as the different user account. If you are having trouble remembering all of the various accounts you need to test with or are tired of having to log in and out many times, the Drupal 7 Masquerade module can help. It allows you to easily and quickly switch between various users on your Drupal website.
In this episode you will learn:
- How to use the Drupal 7 Masquerade module to switch between users on your Drupal 7 website
- How to configure the quick switch links and blocks for the Drupal 7 Masquerade module
Welcome to another Daily Dose of Drupal, today we’re on Episode Number 32 and we’re going to be going over a module called Masquerade and this module; what it allows you to do is it basically allows you to fake log in or spoof another user on your website and this can be important for a wide variety of reasons.
If you are developing a site that has a lot of users and a lot of different permissions and roles and you would instead of having to log out and log back in as a bunch of different users, having this module installed can make it very easy to switch back and forth between different users. I wouldn’t necessarily recommend installing this on a lot of production sites that just have someone gets access … it could get a little messy but as long as you watch your permissions carefully, it would still be okay but it is one module that I could see use on a lot of development sites especially bigger Drupal websites that have a lot of features and a lot of permissions.
So we’ll go ahead and get started; it’s going to be a real simple module and I’m sure we’ll get to this pretty quickly here. So I have a Drupal 7 Test site, go ahead and download the module, make sure I know how to spell it here and we will go ahead and go to the modules page, scroll down and find masquerade module, there it is, go ahead and hit Save. Now after it’s been saved we can configure the permissions which we’ll take a look at that.
There are three Permissions in the Masquerade Module; one would be to allow you to masquerade as a user, one would be the masquerade as Admin which is the Site Admin User ID No.1 and the other one is to administer masquerade. Obviously you should be very careful giving up these permissions and only give them to administrators especially on Live or Production websites.
If we come back in and go to Configure there’s a couple of things here; so it says roles that are considered administrators from masquerading, so we’ll go ahead and select administrator there and now it allows you to enter user names of accounts so that you can easily switch back and forth between users.
So we have a new site here so we don’t have any users so go ahead and create a couple of users; so I’ll create Test User here and I’ll have them be in authenticated user and I’m also going to add a role and we will call this role Site Reviewer; maybe you’re building a blog and you wanted some users be able to review content or do specific things with content but not fully administer the site.
So if you come in and edit some permissions and give them the ability to … we don’t really have too many options here but we could allow them to perhaps view User Profiles, so go ahead and save this and if we come back to the roles we want to make sure if we look at … go ahead and look at all of them at once here; so the only ones who can view User Profiles are Site Reviewer and Administrator. So go ahead and create one more user and we’ll call this user Reviewer and I want to give them the reviewer role, we’ll go ahead and save that, make sure I get the passwords right.
So now if we come in we have our three different users, so the next step is to actually come out to our Masquerade settings and we’ll type in … let’s say we want to easily switch between reviewer but we also want the reviewer and test user to show up in the block and I’ll show you what that is here in just a second but we’ll start by going to the homepage.
You’ll see that there’s a little link here; the navigation that says Masquerade as Reviewer. So you can see I have the Admin bar here, I’m logged in as Shane who’s user ID number 1 account. So if I go to Masquerade as reviewer all of a sudden I am now logged in … if I go to my account as the reviewer user. I can do everything that the reviewer user would be able to do if they were logged in.
I didn’t have to logged out … remember a bunch of different passwords that just made it very easy and now there’s a link to switch back. So if we go and go ahead to Structure Blocks; there’s a Masquerade Block in here, we’ll go ahead and add that to the first sidebar and come back to the homepage and now you’ll see … this is where we edit those multiple users so you can have the block showing when you really need to switch back and forth between a bunch of different users.
Now if we switch to Test 1 you’ll notice that we’re now logged in as Test 1 and we can of course switch back, if we come back here you’ll notice that this user will say Shane is User/1 so we’ll go ahead and go back to Test 1 and we will try to get to that page; you’ll notice we’ll get access to that, if we switch back and come in as reviewer, go to User/1 page you’ll notice we can get to that user profile.
So as you can see it’s a very simple module but it serves its purpose very well of allowing you to spoof or logged in or switch back and forth between different users without having to go to the full log-out, log-in process in managing a bunch of different accounts.
Go ahead and give it a try and let me know what you think, if you have any other Drupal Modules that you want me to go over, any other topics you want me to cover, go ahead and contact me on Twitter @smthomas3 or come to codekarate.com, click on Contact or find some other way to get a hold of me. Until next time; thanks for watching the Daily Dose of Drupal.