CS Nuggets

This blog is for addons, bugs, fixes, and issues pertaining to Community Server.

July 2006 - Posts

CS: Automatically setting the theme of New Users

The themes for new users is always set to "default" when a new account is created.  Since the "Anonymous" user account is used when a user is not logged in, or doesn't have an account. you would think that a new account would adopt the settings from this account.  Since they don't, I created the patch below.  If you are unable to make changes to the SDK, I have placed a link at the end of this post for an addon that you can download.

I added 1 line of code to 2 different source files to achive the result.  These changes are for CS 2.0/2.1 and both ASP.NET (1.1/2.0) platforms.  You will need to make these changes to the SDK and have a compiler to compile the changes.  Listed below are the 2 methods that were changed:

File: CommunityServerControls(20)/User/CreateUser.cs
Class: CommunityServer.Controls.CreateUser
Method: CreateUser_Click(Object sender, EventArgs e):

After the lines:

// Set the Anonymous flag to false
user.IsAnonymous = false;

insert:

// Set Theme to that of the Anonymous user
account user.Theme = Users.GetAnonymousUser().Theme;

File: CommunityServerWeb(20)/ControlPanel/Membership/UserAdd.aspx.cs
Class: CommunityServer.ControlPanel.Membership.UserAdd
Method(CS 2.0): createButton_Click(Object sender, EventArgs e)
Method(CS 2.1): GetUserFromForm(Object sender, EventArgs e):

After the lines:

// try to create the new user account
User user = new User();
user.Username = username.Text;
user.Email = email.Text;
user.Password = password.Text.Trim();
//user.PasswordFormat = CSContext.Current.SiteSettings.PasswordFormat;
user.AccountStatus = UserAccountStatus.Approved;
user.IsAnonymous = false;

insert:

// Set Theme to that of the Anonymous user account
user.Theme = Users.GetAnonymousUser().Theme;

The first method takes care of the user account created by a user and the second method takes care of an account created by an administrator from the control panel.  If you want to use more of the settings from the "Anonymous" user, you can modify the inserted code to include more properties.

 

Addon Option:

I also wrote an addon for those who unable to make changes to the SDK and compile a new set of DLLs for themselves.  This DLL is for the ASP.NET 2.0 version of the site and should work on CS 2.x.  Here is the link to the Addon DLL, which is available from this site.  If you have any trouble with it, just remover the the entry from your communityserver.config file to restore operations.

CS: BUGFIX: CommunityServer.Components.HtmlScrubber: Removing spaces

The CommunityServer.Components.HtmlScrubber is removing spaces from "src" and "href" attributes, which it shouldn't be doing.  If you use the "basic blue" theme, or any other theme that has a space in it, images may not display.  The following changes correct the issue:

CommunityServer.Components.HtmlScrubber.cs:

Change line 61 from:

static Regex filterdCharacters = new Regex("\\=|\\\"|\\'|\\s|\"'", RegexOptions.Compiled);

to:

static Regex filterdCharacters = new Regex("\\=|\\\"|\\'|\"'", RegexOptions.Compiled);

Change line 63 from:

static Regex bannedChars = new Regex("\\s", RegexOptions.Compiled);

to:

static Regex bannedChars = new Regex("", RegexOptions.Compiled);