Enable/disable user

Posted by Community Admin on 03-Aug-2018 21:20

Enable/disable user

All Replies

Posted by Community Admin on 05-Oct-2011 00:00

Hi

What programmatic feature can I use in SF to enable/disable a user from logging in? A code example would be helpful.

Thanks

Regards

Posted by Community Admin on 06-Oct-2011 00:00

Hi John,

The code below works for me fine:

UserManager manager = UserManager.GetManager();
User user = manager.GetUser("testuser");
user.SetIsLockedOut(true);
user.SetLastLockoutDate(DateTime.UtcNow);
 
//uncomment to unlock a user
//user.UnlockUser();
 
manager.SaveChanges();

I hope this helps,
Anton

Posted by Community Admin on 10-Oct-2011 00:00

Hello ,

The easiest way would be to set the IsApproved  property of the user - it gets or sets whether the membership user can be authenticated. For example:

public virtual void ChangeStatus(User user, string command)
       
           var manager = UserManager.GetManager();
           var currentUser = manager.GetUser(user.Id);
           if (currentUser != null)
           
               if (command == "Disable")
               
                   currentUser.IsApproved = false;
               
               else // we assume it is allow
               
                   currentUser.IsApproved = true;
               
               manager.SaveChanges();
           
       


Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed