public async void Test_GivenAnUnknownUser_WhenPasswordSignIn_ThenReturnSigninResultFailed()
        {
            var         signinResult = SignInResult.Failed;
            CognitoUser user         = null;

            userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny <string>())).Returns(Task.FromResult(user)).Verifiable();
            var output = await signinManager.PasswordSignInAsync("userId", "password", true, false).ConfigureAwait(false);

            Assert.Equal(signinResult, output);
            userManagerMock.Verify();
        }
コード例 #2
0
        public async Task <IActionResult> LoginPost(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false).ConfigureAwait(false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);


            if (result.Succeeded)
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }

            ModelState.AddModelError(string.Empty, "Invalid username or password.");

            return(View(model));
        }