示例#1
0
        private async Task <IActionResult> LoginByAspNetIdentity(LoginInputModel model, AuthorizationRequest context)
        {
            UserViewModel userIdentity;

            if (model.IsUsernameEmail())
            {
                userIdentity = await _userManageAppService.FindByEmailAsync(model.Username);
            }
            else
            {
                userIdentity = await _userManageAppService.FindByUsernameAsync(model.Username);
            }

            if (userIdentity == null)
            {
                await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials"));

                ModelState.AddModelError("", AccountOptions.InvalidCredentialsErrorMessage);
            }

            if (userIdentity != null)
            {
                var result = await _signInManager.PasswordSignInAsync(userIdentity.UserName, model.Password, model.RememberLogin, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    return(await SuccessfullLogin(model, userIdentity, context));
                }
                else
                {
                    await FailedLogin(model, result, userIdentity);
                }
            }

            // something went wrong, show form with error
            var vm = await BuildLoginViewModelAsync(model);

            return(View(vm));
        }
示例#2
0
        public async Task <IActionResult> Login(LoginInputModel model, string button)
        {
            // the user clicked the "cancel" button
            var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);

            if (button != "login")
            {
                if (context != null)
                {
                    // if the user cancels, send a result back into IdentityServer as if they
                    // denied the consent (even if this client does not require consent).
                    // this will send back an access denied OIDC error response to the client.
                    await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);

                    // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
                    return(Redirect(model.ReturnUrl));
                }
                else
                {
                    // since we don't have a valid context, then we just go back to the home page
                    return(Redirect("~/"));
                }
            }

            if (ModelState.IsValid)
            {
                UserViewModel userIdentity;
                if (model.IsUsernameEmail())
                {
                    userIdentity = await _userManageAppService.FindByEmailAsync(model.Username);
                }
                else
                {
                    userIdentity = await _userManageAppService.FindByUsernameAsync(model.Username);
                }

                if (userIdentity == null)
                {
                    await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials"));

                    ModelState.AddModelError("", AccountOptions.InvalidCredentialsErrorMessage);
                }

                if (userIdentity != null)
                {
                    var result = await _signInManager.PasswordSignInAsync(userIdentity.UserName, model.Password, model.RememberLogin, lockoutOnFailure : true);

                    if (result.Succeeded)
                    {
                        return(await SuccessfullLogin(model, userIdentity, context));
                    }
                    else
                    {
                        await FailedLogin(model, result, userIdentity);
                    }
                }
            }

            // something went wrong, show form with error
            var vm = await BuildLoginViewModelAsync(model);

            return(View(vm));
        }
示例#3
0
        public async Task Should_Not_Find_Email()
        {
            var result = await _userManagerAppService.FindByEmailAsync(_faker.Person.Email);

            result.Should().BeNull();
        }