예제 #1
0
        public async Task <Unit> Handle(CreateAccountCommand request, CancellationToken cancellationToken)
        {
            var newPassword = new PasswordCredential();

            newPassword.SetPassword(request.Password, _passwordHashingService, _securePasswordSaltGenerator);

            var newEmailAddress = new AccountEmailAddress()
            {
                EmailAddress = request.EmailAddress
            };

            var newAccount = new Account()
            {
                Username           = request.Username,
                PasswordCredential = newPassword
            };

            newAccount.Emails.Add(newEmailAddress);

            newAccount.PrimaryEmail = newEmailAddress;

            await _unitOfWork.Accounts.CreateAsync(newAccount);

            await _unitOfWork.SaveChangesAsync();

            newEmailAddress.SendVerificationRequest(_emailVerifierService, _alphanumericTokenGenerator);

            await _unitOfWork.SaveChangesAsync();

            return(Unit.Value);
        }