public async Task <IActionResult> LoginAsync(MembersLoginVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } // Check if credentials is valid (and set auth cookie) var success = await mService.TryLoginAsync(viewModel); if (!success) { // Show error ModelState.AddModelError(nameof(MembersLoginVM.Username), "Login failed"); return(View(viewModel)); } // Redirect user if (string.IsNullOrWhiteSpace(viewModel.ReturnUrl)) { return(RedirectToAction(nameof(MyPagesAsync))); } else { return(Redirect(viewModel.ReturnUrl)); } }
public async Task <bool> TryLoginAsync(MembersLoginVM viewModel) { var result = await signInManager.PasswordSignInAsync( viewModel.Username, viewModel.Password, false, false); return(result.Succeeded); }
public IActionResult Login() { MembersLoginVM model = new MembersLoginVM { HeadersVM = GetLoginHeaders(), }; return(View(model)); }
public async Task <IActionResult> Login(MembersLoginVM member) { if (!ModelState.IsValid) { return(View(member)); } else { var result = await service.LoginUserAsync(member); if (result.Succeeded) { return(RedirectToAction(nameof(Index))); } else { return(View(member)); } } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Login(MembersLoginVM model) { if (!ModelState.IsValid) { model.HeadersVM = GetLoginHeaders(); return(View(model)); } await signInManager.SignOutAsync(); var result = await signInManager.PasswordSignInAsync(model.UserName, model.Password, false, false); if (!result.Succeeded) { model.HeadersVM = GetLoginHeaders(); ModelState.AddModelError(nameof(MembersLoginVM.UserName), result.ToString()); return(View(model)); } return(RedirectToAction(nameof(Index))); }
internal async Task <SignInResult> LoginUserAsync(MembersLoginVM member) { return(await signInManager.PasswordSignInAsync(member.UserName, member.PassWord, false, false)); }