How to Add Login-as-User button to Edit User Page in AbleCommerce 7

by Joe Payne 20. July 2011 10:07

Introduction

This modification is so simple to do, yet so useful once you do it.  How many times have you had to look up a user account, edit their account to view some detail and then decide you need to log in as that user?  Or even worse, create a brand new user account and immediately need to log in as that user?

Well for me it happens a lot.  I often view a user’s order history before deciding my next action.  The easiest way to do that (for me) is to search for the user in Admin/People/Users and then hit the Orders tab.  But the problem is once you’ve edited the user, there’s no way to log in as that user.  You have to hit the back button and do it from the main User Search page.

What’s worse is if you want to do it for a brand new user.  There’s no easy way to log in as that newly created user after creating the new account.  You have to return the User Search page, re-enter the email address again, search and finally hit the Login icon button.  YAWN!  Smile

Wouldn’t it be handy to be able to log in as that user account right from the Edit User page?

This modification will add a nifty little Login-As-User button to the top of your Edit User page.  It’s at the top for a reason – that way it’s always available no matter what tab you’re viewing.

Code Changes

FIrst you need to find your /Admin/People/Users/EditUser.aspx file and edit it with your favorite text editor.  In the file, find this code near the top:

<div class="pageHeader">
    <div class="caption">
        <h1><asp:Localize ID="Caption" runat="server" Text="Edit User: {0}"></asp:Localize></h1>
    </div>
</div>

Once you find this section of code, replace it with this new code:

<div class="pageHeader">
    <div class="caption">
        <h1><asp:Localize ID="Caption" runat="server" Text="Edit User: {0}"></asp:Localize>&nbsp;&nbsp;<asp:Button ID="btn_LoginUser" runat="server" Text="Login As User" AlternateText="Login as User" ToolTip="Login As User" OnClick="btn_LoginUser_Click"/></h1>
    </div>
</div>

 

Save the file once the changes are made.  The change you just made adds the button to the page.  However we still need some logic on the programming side so the server knows what to do when the button is clicked.

To add the programming logic, edit your /Admin/People/Users/EditUser.aspx.cs file with your favorite text editor.  Find this section of code at the very top:

using CommerceBuilder.Utility;

 

and change it to look like this:

using CommerceBuilder.Utility;
// BEGIN MOD:  AbleMods.com
// 7/20/2011
using System.Web.Security;
// END MOD: AbleMods.com

 

Now move further down the file and find this code:

protected void ShowHideDisabledAlert() 
{
    if (IsDisabled.Checked)
        IsDisabled.Text = "This account is disabled.";
    else
        IsDisabled.Text = string.Empty;
}

And replace it with this:

protected void ShowHideDisabledAlert() 
{
    if (IsDisabled.Checked)
        IsDisabled.Text = "This account is disabled.";
    else
        IsDisabled.Text = string.Empty;
}
 
// BEGIN MOD:  AbleMods.com
// 7/20/2011
protected void btn_LoginUser_Click(object sender, EventArgs e)
{
    FormsAuthentication.SetAuthCookie(_User.UserName, false);
    Response.Redirect(NavigationHelper.GetHomeUrl());
}
 
// END MOD: AbleMods.com

Save the changes once you are done.

Testing

The next step in ANY programming change is to test your changes.  So fire up your AbleCommerce store, log into your Admin side and select the People/Users menu option. 

Once you’re on the User Search page, edit an existing user or add a new user account to reach the Edit User page.  Once the Edit User page is displayed, you should see your new button in the caption directly above the tabs.  Click it and see how it works.

Conclusion

Adding nifty little buttons like this one can make your daily work go so much smoother.  Browser-based applications have long been a hassle because of all the additional mouse clicks necessary.   By modifying your AbleCommerce Edit User page to have a new button for Login-As-User, you’ve saved yourself time and stress by simplifying your workload. 

Tags:

Month List