Managing users

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can create a new user:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        // Create new user object

        UserInfo ui = new UserInfo();

 

        // Set properties

        ui.UserName = "Username";

        ui.FirstName = "John";

        ui.LastName = "Jones";

        ui.FullName = ui.FirstName + " " + ui.LastName;

        ui.UserNickName = "nickname";

        ui.IsEditor = false;

        ui.IsGlobalAdministrator = false;

        ui.Email = "john.jones@localhost.local";

        ui.Enabled = true;

 

        // Save object to database

        UserInfoProvider.SetUserInfo(ui);

 

The following sample code shows how you can add a user to the current site:

 

[C#]

 

using CMS.SiteProvider;

using CMS.CMSHelper;

 

...

 

        // Get user object

      UserInfo ui = UserInfoProvider.GetUserInfo("Username");

 

      // If user exists

      if (ui != null)

       {

          // Add user to site

          UserSiteInfoProvider.AddUserToSite(ui, CMSContext.CurrentSite);

       }

 

The following sample code shows how you can assign an avatar to a user:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        // Get user object

        UserInfo ui = UserInfoProvider.GetUserInfo("Username");

 

        // Get avatar object

        AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary("custom");

 

        // If both exist

        if ((ui != null) && (ai != null))

        {

            // Add avatar to user settings

            ui.UserSettings.UserAvatarID = ai.AvatarID;

 

            // Update user object in database

            UserInfoProvider.SetUserInfo(ui);

 

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_membership_managing_users.htm