public void Handle(AddPhoneNumberCommand message)
        {
            var user        = db.Users.WhereUserLoginIs(message.UserName).Single();
            var phoneNumber = Mapper.Map <UserPhoneNumber>(message.PhoneNumber);
            var code        = VerificationCodeManager.GenerateCode();

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

            user.PhoneNumbers.Add(Mapper.Map <UserPhoneNumber>(message.PhoneNumber));
            db.SaveChanges();
        }
Exemplo n.º 2
0
        protected override async Task Handle(AddPhoneNumberCommand message, CancellationToken cancellationToken)
        {
            var user = await db.Users.WhereUserLoginIs(message.UserName).SingleAsync();

            var phoneNumber = mapper.Map <UserPhoneNumber>(message.PhoneNumber);
            var code        = VerificationCodeManager.GenerateCode();

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

            user.PhoneNumbers.Add(mapper.Map <UserPhoneNumber>(message.PhoneNumber));
            await db.SaveChangesAsync();
        }
        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);
        }