/// <summary> /// Delete a user role /// </summary> /// <param name="userRole">User role</param> public virtual void DeleteUserRole(UserRole userRole) { if (userRole == null) throw new ArgumentNullException("userRole"); if (userRole.IsSystemRole) throw new CmsException("System role could not be deleted"); _userRoleRepository.Delete(userRole); _cacheManager.RemoveByPattern(USERROLES_PATTERN_KEY); //event notification _eventPublisher.EntityDeleted(userRole); }
/// <summary> /// Updates the user role /// </summary> /// <param name="userRole">User role</param> public virtual void UpdateUserRole(UserRole userRole) { if (userRole == null) throw new ArgumentNullException("userRole"); _userRoleRepository.Update(userRole); _cacheManager.RemoveByPattern(USERROLES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(userRole); }
protected virtual void InstallUsersAndUsers(string defaultUserEmail, string defaultUserPassword) { var crAdministrators = new UserRole { Name = "Administrators", Active = true, IsSystemRole = true, SystemName = SystemUserRoleNames.Administrators, }; var crRegistered = new UserRole { Name = "Registered", Active = true, IsSystemRole = true, SystemName = SystemUserRoleNames.Registered, }; var crGuests = new UserRole { Name = "Guests", Active = true, IsSystemRole = true, SystemName = SystemUserRoleNames.Guests, }; var userRoles = new List<UserRole> { crAdministrators, crRegistered, crGuests, }; _userRoleRepository.Insert(userRoles); //admin user var adminUser = new User { UserGuid = Guid.NewGuid(), Email = defaultUserEmail, Username = defaultUserEmail, Password = defaultUserPassword, PasswordFormat = PasswordFormat.Clear, PasswordSalt = "", Active = true, CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow, }; adminUser.UserRoles.Add(crAdministrators); adminUser.UserRoles.Add(crRegistered); _userRepository.Insert(adminUser); //set default user name _genericAttributeService.SaveAttribute(adminUser, SystemUserAttributeNames.FirstName, "Phat"); _genericAttributeService.SaveAttribute(adminUser, SystemUserAttributeNames.LastName, "Nguyen"); //search engine (crawler) built-in user var searchEngineUser = new User { Email = "builtin@search_engine_record.com", UserGuid = Guid.NewGuid(), PasswordFormat = PasswordFormat.Clear, AdminComment = "Built-in system guest record used for requests from search engines.", Active = true, IsSystemAccount = true, SystemName = SystemUserNames.SearchEngine, CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow, }; searchEngineUser.UserRoles.Add(crGuests); _userRepository.Insert(searchEngineUser); //built-in user for background tasks var backgroundTaskUser = new User { Email = "*****@*****.**", UserGuid = Guid.NewGuid(), PasswordFormat = PasswordFormat.Clear, AdminComment = "Built-in system record used for background tasks.", Active = true, IsSystemAccount = true, SystemName = SystemUserNames.BackgroundTask, CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow, }; backgroundTaskUser.UserRoles.Add(crGuests); _userRepository.Insert(backgroundTaskUser); }