private Task PublishAccountCreatedIntegrationEvent( Guid userId, CancellationToken cancellationToken) { var accountCreatedIntegrationEvent = new AccountCreatedIntegrationEvent(userId, "1230568221-201"); #pragma warning disable 4014 Task.Run(() => _eventBus.Publish(accountCreatedIntegrationEvent), cancellationToken); return(Task.CompletedTask); }
public async Task <bool> Handle(AddAccountCommand req, CancellationToken cancellationToken) { var accountCreatedIntegrationEvent = new AccountCreatedIntegrationEvent(req.CustomerId); await _integrationEventLogService.AddAndSaveEventAsync(accountCreatedIntegrationEvent); Account account = new Account(req.CustomerId, "the account is opened"); await _accountRepository.CreateAsync(account); return(await _accountRepository.UnitOfWork.SaveEntitiesAsync()); }
public async Task HandleAsync(CreateAccountCommand command, CancellationToken cancellationToken = default) { var emailIsNotTakenVerificationResult = await _accountVerificationService.VerifyEmailIsNotTakenAsync(command.Email); if (!emailIsNotTakenVerificationResult.Success) { throw new ConflictException(emailIsNotTakenVerificationResult.Errors); } await _accountCreatorService.CreateAsync(command.AccountId, command.Email, command.Password, command.CorrelationId); var accountCreatedIntegrationEvent = new AccountCreatedIntegrationEvent(command.CorrelationId, command.AccountId, command.Email, string.Empty); await _integrationEventBus.PublishIntegrationEventAsync(accountCreatedIntegrationEvent); }
public async Task <ExternalLoginResultOutput> ExecuteAsync(string scheme) { var authResult = await _authenticationService.AuthenticateAsync(scheme); if (!authResult.Succeeded) { throw authResult.Failure; } var emailClaim = authResult.Principal.FindFirst(ClaimTypes.Email); var correlationId = Guid.NewGuid(); var account = await _accountProviderService.ProvideAccountForExternalLoginAsync(emailClaim.Value, correlationId); if (account.DomainEvents.Any(x => x.GetType() == typeof(AccountCreatedDomainEvent))) { var pictureClaim = authResult.Principal.FindFirst("picture"); var picture = pictureClaim != null ? pictureClaim.Value : string.Empty; var accountCreatedIntegrationEvent = new AccountCreatedIntegrationEvent(correlationId, account.Id, account.Email, picture); await _integrationEventBus.PublishIntegrationEventAsync(accountCreatedIntegrationEvent); } var claims = await _accountClaimsCreatorService.CreateAccountClaimsAsync(account); var externalSignInTask = _signInService.ExternalSignInAsync(account.Id, account.Email, scheme, claims); var signOutTask = _signOutService.SignOutAsync(scheme); var returnUrl = authResult.Items is null || !authResult.Items.ContainsKey("returnUrl") || string.IsNullOrWhiteSpace(authResult.Items["returnUrl"]) ? "~/" : authResult.Items["returnUrl"]; var authRequest = await _authorizationService.GetAuthorizationRequestAsync(returnUrl); await Task.WhenAll(externalSignInTask, signOutTask); return(new ExternalLoginResultOutput(returnUrl, authRequest?.IsNativeClient)); }