1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Enable/disable user

Enable/disable user

3 posts, 0 answered
  1. John
    John avatar
    97 posts
    Registered:
    11 Jan 2011
    05 Oct 2011
    Link to this post

    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

  2. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    06 Oct 2011
    Link to this post
    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
  3. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    10 Oct 2011
    Link to this post
    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
3 posts, 0 answered