Archive

Archive for May, 2009

Virtualuser in Sitecore 6

12/05/2009 Leave a comment

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;
}
}

Advertisements
Categories: C#, Sitecore 6 Tags: ,

Virtualuser in Sitecore 5.3

04/05/2009 Leave a comment

If you want to create a user that doesn’t persist in database a virtualuser is the way to go.
It is very simple to setup the user and login him/her into sitecore. The code is ready to integrate into your own little virtualuser class. It is possible to setup most of the ordinary sitecore user item properties, but it is not required, in the following I made possible to set if the user should have Administrator rights or not.
We off course needs to include the sitecorekernel.dll V5.3

using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.SecurityModel;
public class MyVirtualUser{
//Setup correct domain for user
private readonly Domain _domain = new Domain("sitecore", "security");
//This is a Sitecore useritem

private UserItem _userItem;

public User(string userName, bool isAdministrator)

//Make new id need for creating the virtual user
ID userId = ID.NewID;<br>

//Build the virtualuser, from the id and the given username
_userItem = _domain.BuildVirtualUser(userId, userName);
//We need to go into "editmode" or edit the flag for the setting
// isAdminsitrator
using (new EditContext(_userItem.InnerItem))
{
_userItem.IsAdministrator = isAdministrator;
}
}
public bool Login(){
//Try to login the user
DomainAccessResult accessResult = _domain.Login(_userItem);
return accessResult.Success;
}
}

A followup to sitecore 6 willl be out soon.

Categories: C#, Sitecore 5 Tags: ,

Scrollbar

02/05/2009 Leave a comment

First of is this simple css pearl.

Could something be more annoying then your content jumping on your website because of the scrollbar.

Would it be nice if the scroll bar always was showen but only active on page where content can’t fit in the main part ?

The answer is simple:


html
 {
 overflow-y:scroll;
 }

Categories: CSS Tags: