public async Task Create_should_add_user()
        {
            var identity = CreateIdentity(found: false);

            var values = new UserValues
            {
                Email = identity.Email
            };

            SetupCreation(identity, 1);

            await sut.CreateAsync(values.Email, values);

            A.CallTo(() => userEvents.OnUserRegistered(A <IUser> .That.Matches(x => x.Identity == identity)))
            .MustHaveHappened();

            A.CallTo(() => userEvents.OnConsentGiven(A <IUser> .That.Matches(x => x.Identity == identity)))
            .MustNotHaveHappened();

            A.CallTo(() => userManager.AddToRoleAsync(identity, A <string> ._))
            .MustNotHaveHappened();

            A.CallTo(() => userManager.AddPasswordAsync(identity, A <string> ._))
            .MustNotHaveHappened();

            A.CallTo(() => userManager.SetLockoutEndDateAsync(identity, A <DateTimeOffset> ._))
            .MustNotHaveHappened();
        }
Example #2
0
        public async Task <IActionResult> Consent(ConsentModel model, string returnUrl = null)
        {
            if (!model.ConsentToCookies)
            {
                ModelState.AddModelError(nameof(model.ConsentToCookies), "You have to give consent.");
            }

            if (!model.ConsentToPersonalInformation)
            {
                ModelState.AddModelError(nameof(model.ConsentToPersonalInformation), "You have to give consent.");
            }

            if (!ModelState.IsValid)
            {
                var vm = new ConsentVM {
                    PrivacyUrl = identityOptions.Value.PrivacyUrl, ReturnUrl = returnUrl
                };

                return(View(vm));
            }

            var user = await userManager.GetUserAsync(User);

            user.SetConsentForEmails(model.ConsentToAutomatedEmails);
            user.SetConsent();

            await userManager.UpdateAsync(user);

            userEvents.OnConsentGiven(user);

            return(RedirectToReturnUrl(returnUrl));
        }
Example #3
0
        public async Task <IActionResult> Consent(ConsentModel model, string?returnUrl = null)
        {
            if (!model.ConsentToCookies)
            {
                ModelState.AddModelError(nameof(model.ConsentToCookies), "You have to give consent.");
            }

            if (!model.ConsentToPersonalInformation)
            {
                ModelState.AddModelError(nameof(model.ConsentToPersonalInformation), "You have to give consent.");
            }

            if (!ModelState.IsValid)
            {
                var vm = new ConsentVM {
                    PrivacyUrl = identityOptions.PrivacyUrl, ReturnUrl = returnUrl
                };

                return(View(vm));
            }

            var user = await userManager.GetUserWithClaimsAsync(User);

            if (user == null)
            {
                throw new DomainException("Cannot find user.");
            }

            var update = new UserValues
            {
                Consent          = true,
                ConsentForEmails = model.ConsentToAutomatedEmails
            };

            await userManager.UpdateAsync(user.Id, update);

            userEvents.OnConsentGiven(user);

            return(RedirectToReturnUrl(returnUrl));
        }