public async Task HandleAsync(ResetPassword command) { var operationId = Guid.NewGuid(); await _handler .Run(async() => { await _passwordService.ResetAsync(operationId, command.Email); }) .OnSuccess(async() => { var operation = await _oneTimeSecuredOperationService.GetAsync(operationId); await _bus.PublishAsync(new SendResetPasswordEmailMessage { Email = command.Email, Endpoint = command.Endpoint, Token = operation.Value.Token, Request = Request.From <SendResetPasswordEmailMessage>(command.Request) }); }) .OnCustomError(async ex => await _bus.PublishAsync(new ResetPasswordRejected(command.Request.Id, ex.Message, ex.Code, command.Email))) .OnError(async(ex, logger) => { logger.Error(ex, "Error occured while resetting password"); await _bus.PublishAsync(new ResetPasswordRejected(command.Request.Id, ex.Message, OperationCodes.Error, command.Email)); }) .ExecuteAsync(); }
private async Task PublishSendActivationEmailMessageCommandAsync(User user, Request commandRequest) { var operationId = Guid.NewGuid(); await _oneTimeSecuredOperationService.CreateAsync(operationId, OneTimeSecuredOperations.ActivateAccount, user.Email, DateTime.UtcNow.AddDays(7)); var operation = await _oneTimeSecuredOperationService.GetAsync(operationId); var command = new SendActivateAccountEmailMessage { Email = user.Email, Username = user.Name, Token = operation.Value.Token, Endpoint = _settings.ActivateAccountUrl, Request = Request.From <SendActivateAccountEmailMessage>(commandRequest) }; await _bus.PublishAsync(command); }
public async Task Handle(ResetPasswordInitiatedDomainEvent @event, CancellationToken cancellationToken) { _logger.LogInformation("----- Handling domain event {DomainEventName} ({@Event})", @event.GetGenericTypeName(), @event); var operation = await _oneTimeSecuredOperationService.GetAsync(@event.OperationId); await _massTransitBusService.PublishAsync( new ResetPasswordInitiatedIntegrationEvent(@event.Request.Id, @event.OperationId, @event.Email, @event.Endpoint, $"Reset password for user with email: {@event.Email} initiated."), cancellationToken); await _massTransitBusService.SendAsync( new SendResetPasswordMessageIntegrationCommand(@event.Request, @event.Email, operation.Token, @event.Endpoint), cancellationToken); _logger.LogInformation("----- Domain event {DomainEvent} handled", @event.GetGenericTypeName()); }
protected override async Task Handle(SendActivateAccountMessageCommand command, CancellationToken cancellationToken) { var operationId = Guid.NewGuid(); await _handler .Run(async() => { await _oneTimeSecuredOperationService.CreateAsync(operationId, OneTimeSecuredOperations.ActivateAccount, command.UserId, DateTime.UtcNow.AddDays(7)); await _oneTimeSecuredOperationService.SaveChangesAsync(cancellationToken); }) .OnSuccess(async() => { var operation = await _oneTimeSecuredOperationService.GetAsync(operationId); await _mediatRBus.PublishAsync(new ActivateAccountSecuredOperationCreatedDomainEvent( command.Request, command.UserId, command.Username, command.Email, operation.Id, operation.Token, _appOptions.ActivationAccountUrl), cancellationToken); }) .OnCustomError(async customException => { await _mediatRBus.PublishAsync(new CreateActivateAccountSecuredOperationRejectedDomainEvent( command.Request.Id, command.UserId, operationId, customException.Message, customException.Code), cancellationToken); }) .OnError(async(exception, logger) => { logger.Error( $"Error occured while creating a secured operation for user with id: {command.UserId}.", exception); await _mediatRBus.PublishAsync(new CreateActivateAccountSecuredOperationRejectedDomainEvent( command.Request.Id, command.UserId, operationId, exception.Message, Codes.Error), cancellationToken); }).ExecuteAsync(); }