Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > "Log in as this user" funtionality View modes: 
User avatar
Member
Member
Aon_Vlado - 6/6/2011 9:34:57 PM
   
"Log in as this user" funtionality
I have an unusual task and do not know how to accomplish it. I need to have a user in Support role be able to see all users of the sites and login as any of them. I cannot use cmsdesk UI but basically want to mimic the Administration -> Users tab inside of the main web site. Is there a way to use Admin web parts in the main site? If not what would be the best approach to create a user list and “Log in as this user” functionality?

Thanks,

Vlado

User avatar
Member
Member
kentico_michal - 6/7/2011 1:10:41 AM
   
RE:"Log in as this user" funtionality
Hi Vlado,

You can take inspiration how to accomplish similar user interface in the following file: ~\CMSSiteManager\Administration\Users\User_List.aspx.
It is based on standard UniGrid control that is filled with the dataset retrieved by executing cms.user.selectallview query.
Of course, you do no need to use UniGrid, you can use any standard ASP.NET data-binding control according to your needs.

To log in as the particular user, you need to get the UserInfo object of the user, set authentication cookie and context values:


UserInfo ui = UserInfoProvider.GetUserInfo(userId);
if (ui != null)
{
// Set authentication cookie
FormsAuthentication.SetAuthCookie(ui.UserName, false);

// Set context values
CurrentUserInfo cui = new CurrentUserInfo(ui, true);
CMSContext.SetCurrentUser(cui); CultureHelper.SetPreferredUICulture(cui.PreferredUICultureCode);
}


To see this code in action, I would like to point you to HeaderActions_ActionPerformed method in the ~\CMSSiteManager\Administration\Users\User_Edit_General.aspx.cs file. This method contains code for the Log in as the user functionality.

Best regards,
Michal Legen

User avatar
Member
Member
Aon_Vlado - 6/7/2011 6:35:54 AM
   
RE:"Log in as this user" funtionality
Thank you, Michal. A great advice!
Vlado