Exemplo n.º 1
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));
        }
Exemplo n.º 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.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));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Consent(ConsentModel model, string?returnUrl = null)
        {
            if (!model.ConsentToCookies)
            {
                ModelState.AddModelError(nameof(model.ConsentToCookies), T.Get("users.consent.needed"));
            }

            if (!model.ConsentToPersonalInformation)
            {
                ModelState.AddModelError(nameof(model.ConsentToPersonalInformation), T.Get("users.consent.needed"));
            }

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

                return(View(vm));
            }

            var user = await userService.GetAsync(User);

            if (user == null)
            {
                throw new DomainException(T.Get("users.userNotFound"));
            }

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

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

            return(RedirectToReturnUrl(returnUrl));
        }