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 TaskLogin(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?!
Rajkiran SwainPosted Jun 12, 2017, 3:58 AM
Manikandan MurugesanPosted Jun 11, 2017, 9:26 PM
Once user logs in for the first time you need to set a session variable to true.This session variable will be set to false when user clicks logout button.In the login page you have to add a condition check whether the session variable is true or not.If true then don't show login page.If false then show the login page.