//[ValidateAntiForgeryToken] public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)//how is the second para used ? { if (!ModelState.IsValid) { return(View(model)); } var result = await SignInManager.Authenticate(model);// Can look at the original authenticate method of Id Framwork switch (result) { case SignInStatus.Success: return(RedirectToAction("Index", "Home", new { role = SignInManager.rolevalue })); // This doesn't count login failures towards account lockout // If lockout is requested, increment access failed count which might lock out the user // To enable password failures to trigger account lockout, change to shouldLockout: true //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); default: ModelState.AddModelError("", "AD authentication fails ! Please use your CMA account !"); return(View(model)); } }
public async Task <IActionResult> Login([FromBody] LoginModel login) { IActionResult response = Unauthorized(); if (ModelState.IsValid) { var currentUser = await signInManager.Authenticate(login.Username, login.Password); if (currentUser != null) { var tokenString = BuildToken(currentUser); response = Ok(new { user = currentUser, token = tokenString }); } } return(response); }