Ejemplo n.º 1
0
        public async Task <EmailAddressVerificationResult> Handle(VerifyEmailAddressCommand message,
                                                                  CancellationToken cancellationToken)
        {
            var emailAddress = await db.UserEmailAddresses.FindAsync(message.Id);

            var hash =
                emailAddress.VerificationToken =
                    VerificationCodeManager.GetHash(emailAddress.Value + message.VerificationCode);

            if (emailAddress.VerificationToken != hash)
            {
                return(new EmailAddressVerificationResult
                {
                    Success = false,
                    EmailAddressId = emailAddress.Id
                });
            }

            emailAddress.VerificationToken = null;
            emailAddress.IsVerified        = true;

            return(new EmailAddressVerificationResult {
                Success = true
            });
        }
        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();
        }
Ejemplo n.º 3
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);
        }