public async Task ResetAsync(Guid operationId, string email) { var user = await _userRepository.GetByEmailAsync(email, Providers.Collectively); if (user.HasNoValue) { throw new ServiceException(OperationCodes.UserNotFound, $"User with email: '{email}' has not been found."); } await _oneTimeSecuredOperationService.CreateAsync(operationId, OneTimeSecuredOperations.ResetPassword, email, DateTime.UtcNow.AddDays(1)); }
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); }
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(); }