Change Accounts with the Masquerade Drupal Module

| Drupal

Do you need to check what your users see when they login to your site? Do you often need to troubleshoot issues for your users? If so, the Masquerade module will be a very useful tool.

The Masquerade module allows you to login as any user but using your own password. You can mimic anyone else's login and see exactly what they see. This is very useful on membership sites and sites that require multiple levels of access.

Step 1. Download and install

tutuploadstutuploadsStep_2_6ae5f9e534ab5400b82fa415dd99042a.png

Step 2. Activate and configure

tutuploadstutuploadsStep_3_447f0aed20fafdfcbbcf8457da7bc853.png
  • Click the checkbox.
  • Scroll to the bottom of the page and click Save Configuration. You will see the Permissions and Configure links.
  • Click Configure.

Step 3. Roles and Users

tutuploadstutuploadsStep_4_8ccc7e99fedd1de6741745f9febf5b79.png
  1. Choose "administrator". Any roles can be used for masquerading but it is safer to restrict this to adminstrators only.
  2. If you want to test on particularly user often, add their username here. Their name will appear as a menu link.
  3. If you want to test on particularly user often, add their username here. Their name will appear in the Masquerade block.
  4. Click Save Configuration.

One way to use this efficiently is to create a test user for each role. So you might create a test account for the anonymous user role and another for the authenticated user role. You can then enter the names of the test users into 2 and 3.

Step 4. Give the administrator permission to use Masquerade

tutuploadstutuploadsStep_5._Give_the_administrator_permission_to_use_Masquera.png
  • Go back to the Module Page and click on Permissions.
  • Click the checkboxes to allow administrator access to Masquerade.
  • Scroll to the bottom of the page and Save Permissions.

Step 5. Create a block for quick access to user switching

tutuploadstutuploadsStep_6._Create_a_block_for_quick_access_to_user_switching.png

Go to Structure > Blocks.

tutuploadstutuploadsmedia_1325632124189.png

Find the Masquerade block in the disabled list and choose the region you want to place it in. I am going to put it Sidebar first for this lesson.

tutuploadstutuploadsmedia_1325706817530.png
  • Click Configure on the right side of the Masquerade row, Under Visibility settings.
  • Click Pages and configure.
  • Click Content types. Leave the checkboxes blank for no restrictions, or choose where you might want it.
  • Check the box next to Administrator on the Roles panel.
  • Click Save Block.

Step 6. Test the function of the module from the front end

tutuploadstutuploadsStep_7._Test_the_function_of_the_module_from_the_front_en.png
  • Go to your home page. On the front end you'll see the Masquerade block.
  • Type in a username and click Go and you will now be logged in as that user.
  • If you filled in the Quick Switch Menu and Block user fields in Step 4, you'll see quick links for logging in as admin and the test users.
  • Click the link to one of your test users, and see what happens.
tutuploadstutuploadsmedia_1325633031500.png

You'll get a message that you are now masquerading as the test user.

There will be a link on the Navigation menu "Switch back" Click it and you will be back to the administrator user.

Notice that since you are now logged in as testone, you cannot see the Masquerade block, since we only gave access to administrators to see that. When you switch back it will be there again.

tutuploadstutuploadsmedia_1325633194768.png

Click Log out.

tutuploadstutuploadsmedia_1325633272699.png

You will now be viewing as an anonymous user.

We're getting Access denied because we turned off all permissions for anonymous users, which may be what you want. Probably, though you want some things visible for anonymous users, and some special content visible only to registered users or whatever roles you created. Once you understand this process, you can go back and configure your desired permissions.

In this demo we have three very distinct user experiences and its easy to see exactly what each user role is allowed to see.

Step 7. Alternate access to user switching

tutuploadstutuploadsStep_8._Alternate_access_to_user_switching.png

Go to People and click the name of a user from the list view.

Note: If you want to only use this method, you do not need to create a Masquerade block.

tutuploadstutuploadsmedia_1325633708626.png

1. You will now see a link on the user History that says, "Masquerade as username"

2. If you filled in the field titled "Menu Quick Switch User" in Step 4, you will see a link in the Navigation block that lets you switch to whatever user you specified there. If you left that blank, it will just say "Switch back". and you will switch back to the administrator.

Now you have all the basics. It should make it easier to set up complicated user access control. If you're a beginner it would be a great idea to set up test users for each role and experiment with this.