Virtualuser in Sitecore 6
As promised a followup to virtualusers in sitecore.
This time for sitecore 6. The changes in the security model made to sitecore 6 makes only minor changes in the creation of the virtualusers. One of these changes are that the domain is set in the username.
using Sitecore.Data;
using Sitecore.Security.Authentication;
using Sitecore.Shell.Applications.ContentEditor.Gutters;
public class User {
private readonly Sitecore.Security.Accounts.User _userItem;
public User(string userName, bool isAdministrator) {
//make sure that the username i prefixed with "sitecore"
//this sets the domain for the
userName = "sitecore\\"+userName
_userItem = AuthenticationManager.BuildVirtualUser(userName, true);
//Sitecore 6 needs profile settings for useritem
_userItem.Profile.Initialize(userName, true);
_userItem.Profile.Email = userName + "@something.dk";
_userItem.Profile.IsAdministrator = isAdministrator;
//save the useritem
_userItem.Profile.Save();
}
public bool Login() {
bool loginResult = AuthenticationManager.Login(_userItem.Name);
//Used for setting the show locked item in the gutter
ID gID = new ID("{1A005ECC-65B4-4A00-88BE-A6FA7D64BEA3}");
//Id for showing all locked items
GutterManager.ToggleActiveRendererID(gID);
return loginResult;
}
}
Categories: C#, Sitecore 6
C#, Sitecore
Comments (0)
Trackbacks (0)
Leave a comment
Trackback