Exemple #1
0
        public ICommandResult Handle(AuthenticateCustomerCommand command)
        {
            //Validar command
            command.Validate();

            //Validar command
            command.Validate();

            if (!_customerRepository.CheckEmail(command.Email))
            {
                return(new GenericCommandResult());
            }

            var customer = _customerRepository.GetByEmail(command.Email);

            if (!_codeRepository.CheckCode(command.Code, customer.Id))
            {
                return(new GenericCommandResult(false, "Código inválido", null));
            }

            var token = _tokenService.GenerateToken(customer);

            _codeRepository.MarkAsInvalid(command.Code, customer.Id);

            return(new GenericCommandResult(true, "Validação concluída", new { token }));
        }