I have define one column ( IsEnabled) in my database table AspNetUsers on wich I want to enable / disable users ro login in on my login page.
The code in my Account controller is:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
string viewName = String.Empty;
try
{
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
if (result == SignInStatus.Success)
{
if (model.IsEnabled == 0)
{
AuthenticationManager.SignOut(); stavime.
ModelState.AddModelError("", Resources.UnableToLoginText);
}
else {
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", Resources.UnableToLoginText);
}
}
catch {
//ModelState.AddModelError("", Resources.UnableToLoginText);
}
return View(_ViewForLogin);
}
In my LoginViewModel I have:
public class LoginViewModel
{
//[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }
[Required]
[Display(Name = "User Name")]
[EmailAddress]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Rembember Me")]
public bool RememberMe { get; set; }
[Display(Name = "IsEnabled")]
public int IsEnabled { get; set; }
}
The problem is that I can not read IsEnabled value form database ( The value is always 0) and because that my check does not work?!