Exemple #1
0
        public async Task <CommandResponse> Handle(SolicitarNovaSenhaCommand request, CancellationToken cancellationToken)
        {
            var busca = await _repository.Buscar(u => u.Email.Endereco.Equals(request.Email));

            if (!busca.Any())
            {
                await _mediator.Publish(new DomainNotification(this.GetType().Name, "O e-mail fornecido não possui nenhum registro."));

                return(await Task.FromResult(CommandResponse.Fail));
            }

            var usuario = busca.SingleOrDefault();
            var token   = usuario.GerarTokenDeRefinicaoSenha();

            _repository.AdicionarTokenDeRedefinicao(token);

            if (await Commit())
            {
                await _mediator.Publish(new NovaSenhaSolicitadaEvent(usuario.Nome.PrimeiroNome, usuario.Email.Endereco, token.Token));
            }

            return(await Task.FromResult(CommandResponse.Ok));
        }