Approving Users
Hi all, I am somewhat new to developing for Sitefinity.
I need to provide a way for administrators to approve users that have registered on a Sitefinity 7 site. Ideally, I need to add a button or checkbox to the Edit User Profile screen that sets the value of the User.IsApproved boolean field.
I am setting the IsApproved flag to false when the user registers, but I can't find documentation on how to allow an administrator to set the flag to true from the Sitefinity backend. The best documentation I could find is located here: docs.sitefinity.com/for-developers-users-api
What is the recommended way to approve a newly registered user?
Thanks!
Hi Matthew,
Currently, the only way to approve the users (if they have not properly activated their accounts after registration) is by setting the IsApproved property of the user to true using the API. Here is a sample code which you can use to activate an account:
var userMan = UserManager.GetManager(
"Default"
);
//you won't need this if you'll be doing it from your site's backend and you already have sufficient privileges to perform this action
userMan.Provider.SuppressSecurityChecks =
true
;
//you can also use one of the other overloads of userMan.GetUser()
var user = userMan.GetUserByEmail(
"test@test.com"
);
if
(user !=
null
)
user.IsApproved =
true
;
userMan.SaveChanges();
Thanks, Sabrie. I think Sitefinity should have a standard way to mark users as approved, so I voted on adding the feature.
To resolve my issue, I wound up defining my own instance of the UserEditDialog. This allowed me to use Javascript to set the IsApproved flag to the value of a checkbox I added to the dialog.