Monday, December 27, 2010

Disable Sitecore User Account on Creation

When Creating a new User in code via the CreateUserWizard or simply by calling Sitecore.Security.Account.User.Create() the user is approved by default.
To alter this behavior you will need to get the user and update the IsApproved field.

If you are simply using Sitecore.Security.Account.User.Create() then you just need to do the following:

                    // Create a new user in the system
                    newUser = User.Create(userName, password);

                    // Since we just created the user they should not be approved yet.
                    MembershipUser user = GetMembershipUserByUserName(userName);
                    user.IsApproved = false;
                    Membership.UpdateUser(user);

If you are using the wizard here is the event code.

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles CreateUserWizard1.CreatedUser

        ' Set Account to IsApproved=False
        Dim Usr As MembershipUser = Membership.GetUser(Me.CreateUserWizard1.UserName, True)
        Usr.IsApproved = False
        Membership.UpdateUser(Usr)

    End Sub

I got this information from a forum post about
How to send confirmation email to newly registering user via CreateUserWizard

If you found this article useful be sure to pass it on. If you have any tips, tricks or resources you would like to share with the Guild please email them to sitecoreguild@outlook.com

Friday, December 10, 2010

Configuring Custom User Profiles Properly

When it comes to custom user profiles, Sitecore is very flexible but sometimes that comes at a price. The description of setting up custom user profiles is straight forward in the documentation and as long as you only wish to access the properties in code it works great, however if you wish to access the properties from the database level you will need to add a few extra entries to the web.config.

STEP 1: Set up the Custom User Profile as documented in the Sitecore Security API Cookbook available on the Sitecore Developer Network

STEP 2: Make note of the custom properties you created and open the web.config. Search for "SC_UserData" Add items similar to this item below the existing SC_UserData item. Change the data type and field name to match the fields you added.

STEP 3: Read the following article to see how to get the aspnet profile properties from SQL Server

STEP 4: Create your user in the admin once created edit the user and click change to set your custom profile. Add data to the fields and check if its appearing for in SQL

STEP 5: When you create a user in code you will have to add the custom profile to them. as documented in the Sitecore Security API Cookbook available on the Sitecore Developer Network

If you found this article useful be sure to pass it on. If you have any tips, tricks or resources you would like to share with the Guild please email them to sitecoreguild@outlook.com