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!  

Creating a new user

 

[C#]

 

using CMS.SiteProvider;

 

// Create UserInfo

UserInfo user = new UserInfo();

 

// Set some properties

user.UserName = "Alice";

user.FirstName = "Alice";

user.LastName = "Cooper";

user.FullName = "Alice Cooper";

user.Email = "alice.cooper@domain.com";

user.IsEditor = true;

user.PreferredCultureCode = "en-us";

 

// Create new user

CMS.SiteProvider.UserInfoProvider.SetUserInfo(user);

 

Selecting and updating a user

 

[C#]

 

using CMS.SiteProvider;

 

// Get UserInfo of the specified name

UserInfo user = CMS.SiteProvider.UserInfoProvider.GetUserInfo("Alice");

 

if (user != null)

{

  // Change some values

  user.Enabled = false;

 

  // Update the UserInfo

  CMS.SiteProvider.UserInfoProvider.SetUserInfo(user);

}

 

Deleting a user

 

[C#]

 

CMS.SiteProvider.UserInfoProvider.DeleteUser("Alice");

 

Getting the list of sites the user belongs to

 

[C#]

 

using CMS.SiteProvider;

 

// Get UserInfo of the specified name

UserInfo user = CMS.SiteProvider.UserInfoProvider.GetUserInfo("Alice");

 

if (user != null)

{

  // Get table with user's sites

  DataTable table = CMS.SiteProvider.UserInfoProvider.GetUserSites(user.UserID);

 

  if (table != null)

  {

    // Process table ...

  }

}

 

Adding user to a site

 

[C#]

 

// Use UserName and SiteName to add user to site

CMS.SiteProvider.UserInfoProvider.AddUserToSite("Alice", CMS.CMSHelper.CMSContext.CurrentSite.SiteName);

 

Removing user from a site

 

[C#]

 

// User UserName and SiteName to remove user from site

CMS.SiteProvider.UserInfoProvider.RemoveUserFromSite("Alice", CMS.CMSHelper.CMSContext.CurrentSite.SiteName);

 

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