LDAP User List Update
I am trying to update every LDAP user (which are all using the Basic Profile).
I want all "is public profile" to be updated to TRUE.
I cannot seem to find specific documentation to do this...
Basically the script to do this should:
Loop through all users
Change ispublic flag to TRUE
Update profile.
Thanks!!!!
Doc is right here: docs.sitefinity.com/for-developers-modify-user-profiles
Obviously you could use usermanager to get all users and loop, or instead on the login event just set it to true for the user that just logged in (so more on demand)
Hi Steve and thanks,
I tried the following - I am starting off by simply updating the About field.
This didn't affect anything.
public static void GetAllProfilesAndUpdate()
var userManager = UserManager.GetManager();
var users = userManager.GetUsers();
foreach (var user in users)
UserProfileManager profileManager = UserProfileManager.GetManager();
UserManager ldapUserManager = UserManager.GetManager("LdapUsers");
User account = ldapUserManager.GetUser(user.Id);
if (account != null)
SitefinityProfile profile = profileManager.GetUserProfile<SitefinityProfile>(account);
profile.SetValue("About", "Test From Program");
profileManager.SaveChanges();
If anyone from Telerik can chime in here - it would be extremely helpful. I have an urgent project that needs this taken care of...I got 2000 users that I need to be "public"....thanks!!!
Hello Andy,
We have answered you in the support ticket that you opened for this topic. Feel free to share the information provided with the community.
FYI for everyone:
LDAP users may show up in the Admin>User list, but unless someone has edited their profile, they do NOT have a Sitefinity profile yet. They must have profiles created for them before they are considered "public" to the system.
The code below should read LDAP users, and create a profile first, summarily setting each profile to Public.
public static void GetAllProfilesAndUpdate()
var userManager = UserManager.GetManager("LdapUsers");
var users = userManager.GetUsers();
foreach (var user in users)
UserProfileManager profileManager = UserProfileManager.GetManager();
SitefinityProfile profile = null;
profile = profileManager.GetUserProfiles(user.Id).Where(p => p.GetType().FullName == typeof(SitefinityProfile).FullName).SingleOrDefault() as SitefinityProfile;
if (user.LastName != "" && user.Email != null && profile == null)
SitefinityProfile userProfile = null;
userProfile = profileManager.CreateProfile(user, Guid.NewGuid(), typeof(SitefinityProfile)) as SitefinityProfile;
userProfile.SetValue("IsProfilePublic", true);
if (user.LastName != "")
profileManager.SaveChanges();
userManager.Provider.SuppressSecurityChecks = true;
userManager.SaveChanges();
userManager.Provider.SuppressSecurityChecks = false;
Hi guys,
I've tested the last example of Andy for the same issue with LDAP users in a User list. There's no public profile page. In my code it fires on Session Start in the Global.asax file and is configured for the current user.
The changes are being saved for each user where CreateProfile has been called and the IsProfilePublic is set to true. But still there's no Sitefinity profile page untill someone edits it.
protected
void
Session_Start(
object
sender, EventArgs e)
//Check if userprofile exist
var userManager = UserManager.GetManager(
"LdapUsers"
);
Guid userid = SecurityManager.GetCurrentUserId();
var user = userManager.GetUser(userid);
if
(user !=
null
)
UserProfileManager profileManagerUP = UserProfileManager.GetManager();
SitefinityProfile profileUP =
null
;
profileUP = profileManagerUP.GetUserProfiles(user.Id).Where(p => p.GetType().FullName ==
typeof
(SitefinityProfile).FullName).SingleOrDefault()
as
SitefinityProfile;
if
(user.LastName !=
""
&& user.Email !=
null
&& profileUP ==
null
)
SitefinityProfile userProfile =
null
;
userProfile = profileManagerUP.CreateProfile(user, Guid.NewGuid(),
typeof
(SitefinityProfile))
as
SitefinityProfile;
userProfile.SetValue(
"IsProfilePublic"
,
true
);
profileManagerUP.Provider.SuppressSecurityChecks =
true
;
profileManagerUP.SaveChanges();
userManager.Provider.SuppressSecurityChecks =
true
;
userManager.SaveChanges();
userManager.Provider.SuppressSecurityChecks =
false
;
profileManagerUP.Provider.SuppressSecurityChecks =
false
;
is there something I miss?
Any help will be appreciated!