//[ValidateAntiForgeryToken] public async Task <IActionResult> Login(LoginViewModel model) { if (model == null || string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError("InvalidCredentials", "Invalid credentials."); return(View(model)); } var user = await _userManager.FindByNameAsync(model.Email); if (user == null || string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError("InvalidCredentials", "Invalid credentials."); return(View(model)); } //var adResult = "Ok"; var isValid = await _userManager.CheckPasswordAsync(user, model.Password); var result = await _userManager.CheckPasswordAsync(user, model.Password); //Ad integration var adResult = _directoryService.CheckADUserPassword(user.UserName, model.Password); if (user == null) { ModelState.AddModelError("InvalidCredentials", "Invalid credentials."); return(View(model)); } var properties = new AuthenticationProperties { IsPersistent = true, }; var claims = await _userService.GetClaims(user); var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaims(claims); var principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); if (IsUrlValid(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } return(RedirectToAction("Index", "Home")); }