kpankratov@capprod.com
-
8/15/2008 2:37:36 PM
Creating/Updating User
We have some problems while creating or updating users.
Here is a simple, test method to create new user.
------------------------------------------------------------------------------------------------------------------------------------------------------------------- private string KenticoCreateUser() { // local variables int userID = -1;
try { // init user entity in CMS CMS.SiteProvider.UserInfo ui = new CMS.SiteProvider.UserInfo();
// set user values ui.Email = "capuser@capprod.com"; ui.LastName = "caplast"; ui.FirstName = "capfirst"; ui.FullName = "capfull"; ui.UserName = "capuser@capprod.com"; ui.Enabled = true; ui.IsEditor = false; ui.IsGlobalAdministrator = false;
// create new user CMS.SiteProvider.UserInfoProvider.SetUserInfo(ui);
// get user id userID = ui.UserID;
// set user password CMS.SiteProvider.UserInfoProvider.SetPassword(ui.UserName, "12345");
// set user sites CMS.SiteProvider.UserInfoProvider.AddUserToSite(ui.UserName, "HQPortail"); // set user roles CMS.SiteProvider.UserInfoProvider.AddUserToRole(ui.UserName, "HQMembres", "HQPortail");
} catch { throw; }
// return return userID.ToString(); } ---------------------------------------------------------------------------------------------------------
The lines highlited in yellow, throw the following exception: [TranslationHelper.GetObject]: Event OnGetObject is not initialized, cannot retrieve object code name column name
Once the method above is executed, a new user is created, I can see it in CMS Site Manager user’s list. But, no site is affected to this user and no roles are defined.
Second. If I do this:
try { // set user sites CMS.SiteProvider.UserInfoProvider.AddUserToSite(ui.UserName, "HQPortail"); } catch { } try { // set user roles CMS.SiteProvider.UserInfoProvider.AddUserToRole(ui.UserName, "HQMembres", "HQPortail"); } catch { } I just placed empty try catch blocks to let the code execute even if errors occurs. In that case, the new user is created and is added to sites and roles.
Please, let me know if I am doing something wrong. Waiting for you help, Thank you in advance
|