mojoPortal content management system (as of version 2.2) includes a flexible User Profile System to make it easy to customize the User Profile depending on the purposes of the site. A default installation has a specific set of User Profile Properties, but you can remove Properties that you don't need or add Properties that you do need to make the User Profile more suitable for your purposes.
Note that you are not allowed to have custom properties with names that clash with core user properties. If you do this you will get an error on the UserProfile page. Specifically, you cannot use "UserID", "UserGuid", "Name", "LoginName", "Email", "Password", "PasswordQuestion", and "PasswordAnswer", as these are all core properties.
To add or remove User Profile Properties, you only need to edit the mojoProfile.config file at the root of the site. It is a simple text file and can be edited with any text editor like Notepad. Actually, in order to not lose your custom settings during upgrades, you should copy the mojoProfile.config file and name it CustomProfile.config, then in user.config add/change this setting to point to your custom file:
<add key="mojoProfileConfigFileName" value="CustomProfile.config" />
Note that for a multi site installation you can use a different profile configuration file for each site by adding a config setting like this:
<add key="mojoProfileConfigFileName-2" value="site2profile.config" />
The value can be named as you like, but for it to find your setting the key must be in the shown format where "2" in the example is the site id for site 2 and you can add additional ones for site 3, 4, etc.
There are 4 pages in a mojoPortal site that are populated from the settings in mojoProfile.config
- Admin/ManageUsers.aspx is used by Site Administrators to manage user settings. All User Profile Properties are editable by members of the Admins role.
- Secure/UserProfile.aspx is used by the user to edit his/her own profile properties.
- ProfileView.aspx is a read only page for viewing the profiles of other users
- Secure/Register.aspx is used to Register a User Account in a site and User Profile Properties can be configured so that they are required for Registration.
The first 2 properties in mojoProfile.config are Gender and Web Site Url, and these are good examples that show most of the features of the User Profile system, so we will look at them in detail. First, here is what the properties look like in the mojoProfile.config file.
name (mandatory) - must be unique for each property in the mojoProfile.config file, it is the name of the property. Note that all properties are case sensitive.
type (optional, defaults to System.String)- this setting is used to determine how to render the property.
- System.Boolean renders as a Checkbox for editing the property and in read only mode as an image from the skin folder, true.png or false.png.
- System.DateTime renders in edit mode as a DatePicker.
- For all other types we render a TextBox for editing the property, unless the property has an OptionList configured with at least one Option. In that case we render a DropDownList for editing.
includeTimeForDate (optional defaults to false) - only used when type is set to System.DateTime. If true the DatePicker will also show time.
resourceFile (optional, defaults to ProfileResource) - this is not shown above, ProfileResource corresponds to App_GlobalResources/ProfileResource.resx but you can override it and get resources from a different file. When specifying a resourceFile use the name of a resource file that exists in App_GlobalResources, but leave off the file extension.
labelResourceKey (required or no label will be displayed) - this value is used for the label associated with the property. It is localizable by putting a resource key here that exists in the App_GlobalResources/ProfileResource.resx file. If no resource is found then this property is used for the label directly so it is not required to edit the Resource files but it is recommended.
lazyLoad (optional, defaults to false) - in most cases you should leave this set to false. When set to true, the property will be loaded from the database on demand rather than as a group with the other profile properties. This should only be true for seldom used or particularly expensive to retrieve properties.
showOnRegistration (optional, defaults to false) - if set to true the property will appear on the registration page but the user will not be required to enter a value.
requiredForRegistration (optional, defaults to false) - if set to true, the property will appear on the registration page when a user registers on the site and will require a value.
allowAnonymous (optional, defaults to true) - this setting is for future use, if we need to capture property values from anonymous users. It is not currently used.
visibleToAnonymous (optional, defaults to false) - if the Web.config setting "AllowAnonymousUsersToViewMemberList" is set to true, then anonymous users can see the Member List for the site. On the Member List page there is a "View Profile" link to view the profile of other Members. Setting "visibleToAnonymous" to false means that only authenticated users can see this property on another member's profile view.
visibleToAuthenticated (optional, defaults to true) - applies to the Profile View page. Set this to false for properties that should be visible only to the user or site admins.
visibleToUser (optional, defaults to true) - you may want to have properties that only site administrators can see. Set this setting to false and only site administrators will be able to see the property.
editableByUser (optional, defaults to true) - if you don't want the user to be able to edit this property, set this to false. A user also cannot edit a property if it is not visible.
regexValidationExpression (optional) - enter a RegularExpression here to enforce validation on your property so that only valid values can be entered. See the WebSiteUrl property example below, it has a Regular Expression that enforces that the WebSiteUrl property starts with either http:// or https://. For more on Regular Expressions, you can find a lot of examples for common validation scenarios on this site: http://www.regxlib.com/
If left blank no validation will occur.
regexValidationErrorResourceKey (optional but should be specified if using regexValidationExpression) - when a user enters a value that fails to pass your validation expression, it is a good idea to show a message giving some idea of the expected value. You can enter this message here or add it to the App_GlobalResources/ProfileResource.resx file and just put the key here.
onlyAvailableForRoles (optional, default value is an empty string which means its available to all roles) - sometimes you may want a property to be only available for certain roles. For example if you wanted a property to only be available to members of the Admins and Content Administrators roles, you would put "Admins;Content Administrators", separating each role name with a semicolon.
onlyVisibleForRoles (optional, default value is an empty string which means its visible to all roles) - sometimes you may want a property to be only visible for certain roles. For example if you wanted a property to only be available to members of the Admins and Content Administrators roles, you would put "Admins;Content Administrators", separating each role name with a semicolon. NOTE: the onlyVisibleForRoles setting takes precedence over all other "Visible" settings.
defaultValue (optional) - can be used to specify a default for the property that will be used when new users are created.
includeHelpLink (optional, defaults to false) - if set to true a help link will be displayed next to this property on the UserProfile.aspx or Admins/ManageUsers.aspx page. Members of the Admins or Content Administrators role will then be able to edit the help for this property.
OptionList (optional) - allows you to configure a list of possible options that will appear as a dropdown list.
Note that the WebSiteUrl property renders on the ProfileView.aspx page as a hyperlink to the user's web site. If you have a custom property with "Url" in the name the property will be rendered as a hyperlink. It is up to you to use a regular expression to make sure the value entered by the user in edit mode is appropriate.
For properties that render in edit mode as a TextBox, you can also set a maxLength which determines the maximum number of characters that will be allowed for the property. If maxLength is 0 then there is no limit on the length.
The columns property determines the width of the TextBox. You can also specify a rows property, if rows > 1, then the TextBox will be configured with multiple lines (a textarea in html).
Note that the configuration file is for configuring user properties that show up in the user profile page. It is also possible to create and retrieve arbitrary properties for authenticated users that are never shown on the user profile pages.
SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
string somePropertyValue = siteUser.GetCustomPropertyAsString(propertyName);
I hope this documentation is helpful. If you have any suggestions to improve this documentation please post in the Developer forum on the forums page.
Last Updated: 2011-02-25 by Joe Audette