Asp.Net Mvc4 WebSecurity How to activate or deactivate a user account

1k views Asked by At

I have create an account in mvc4 using the websecurity class as follow :

 WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
  new {  
           EmailAddress = model.EmailAddress, 
           ContactNo = model.ContactNo,
           Password = model.Password
       });

My user have created successfully ... now i want to : activate/deactivate a user whenever i wish.

so that user login only if his account is active otherwise he shouldn't be able to login .

How can i achieve this?

1

There are 1 answers

0
Ali Soltani On BEST ANSWER

You can use UserProfile class for do it. This class located in the AccountModels class which acts as a profile table for each user account. It is here that you'd typically want to include a property named IsActive.

[Table("UserProfile")]
public class UserProfile
{
  [key]
  [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
  public int UserId { get; set; }
  public string UserName { get; set; }
  public string LastName { get; set; }
  public string FirstName { get; set; }
  public string Email { get; set; }
  public bool IsActive { get; set; }
}

You can change IsActive property and check it in login action.

See this post for more information.