Beispiel #1
0
        public async Task <IActionResult> VerifyEmailAddress(VerifyEmailAddressCommand command)
        {
            var result = await mediator.Send(command);

            if (result.Success)
            {
                return(RedirectToAction("Index"));
            }

            throw new Exception("Failed to verify");
        }
        public void Handle(AddEmailAddressCommand message)
        {
            var user         = db.Users.WhereUserLoginIs(message.UserName).Single();
            var emailAddress = new UserEmailAddress {
                Value = message.EmailAddress
            };
            var code = VerificationCodeManager.GenerateCode();

            emailAddress.VerificationToken = VerificationCodeManager.GetHash(emailAddress.Value + code);

            user.EmailAddresses.Add(emailAddress);
            db.SaveChanges();

            var urlCommand = new VerifyEmailAddressCommand
            {
                Id = emailAddress.Id,
                VerificationCode = code
            };

            var url = message.VerificationUrlBuilder(urlCommand);

            mailer.EmailVerificationCode(emailAddress.Value, user.Login, url);
        }
        protected override async Task Handle(AddEmailAddressCommand message, CancellationToken cancellationToken)
        {
            var user = await db.Users.WhereUserLoginIs(message.UserName).SingleAsync();

            var emailAddress = new UserEmailAddress {
                Value = message.EmailAddress
            };
            var code = VerificationCodeManager.GenerateCode();

            emailAddress.VerificationToken = VerificationCodeManager.GetHash(emailAddress.Value + code);

            user.EmailAddresses.Add(emailAddress);
            await db.SaveChangesAsync();

            var urlCommand = new VerifyEmailAddressCommand
            {
                Id = emailAddress.Id,
                VerificationCode = code
            };

            var url = message.VerificationUrlBuilder(urlCommand);

            mailer.EmailVerificationCode(emailAddress.Value, user.Login, url);
        }