コード例 #1
0
        public IndicatorLoginDTO Login(string cpf, string password)
        {
            IndicatorUtil Util = new IndicatorService();

            if (Util.StringIsNull(cpf))
            {
                throw new BadRequestException("CPF deve ser preenchido");
            }

            if (Util.StringIsNull(password))
            {
                throw new BadRequestException("SENHA deve ser preenchida");
            }

            if (_cpfValidate.ValidaCPF(cpf) == false)
            {
                throw new BadRequestException($"CPF inválido: {cpf}");
            }

            Indicator indicator = _repository.GetIndicatorLogin(cpf, password);

            if (Util.ObjectIsNull(indicator))
            {
                throw new NotFoundException("CPF ou SENHA inválidos");
            }

            switch (indicator.Status)
            {
            case Enums.IndicatorStatus.INACTIVE:
                throw new BadRequestException("Este usuário está inativo :c");

            case Enums.IndicatorStatus.BLOCKED:
                throw new BadRequestException("Este usuário está bloqueado :c");
            }

            if (indicator.IsConfirmed.Equals(AccountConfirm.NOT_CONFIRMED))
            {
                throw new BadRequestException("NOT_CONFIRMED");
            }

            // Gera o Token para indicador
            var token = TokenService.GenerateTokenIndicator(indicator);

            IndicatorLoginDTO indicatorLogged = new IndicatorLoginDTO();

            indicatorLogged.Id              = indicator.Id;
            indicatorLogged.CPF             = indicator.CPF;
            indicatorLogged.Email           = indicator.Email;
            indicatorLogged.Name            = indicator.Name;
            indicatorLogged.Status          = indicator.Status;
            indicatorLogged.PaymentAccounts = indicator.PaymentAccounts;
            indicatorLogged.Token           = token;

            return(indicatorLogged);
        }
コード例 #2
0
        public IndicatorLoginDTO RegisterNewAsync(Indicator indicator)
        {
            IndicatorUtil Util = new IndicatorService();

            if (Util.CPFIsEmpty(indicator))
            {
                throw new BadRequestException("CPF deve ser preenchido");
            }

            if (_cpfValidate.ValidaCPF(indicator.CPF) == false)
            {
                throw new BadRequestException($"CPF inválido: {indicator.CPF}");
            }

            if (!Util.ObjectIsNull(_repository.GetIndicatorByCPF(indicator.CPF)))
            {
                throw new BadRequestException($"Já existe um usuário cadastrado com este cpf: {indicator.CPF}, faça login :)");
            }

            if (Util.StringIsNull(indicator.Password))
            {
                throw new BadRequestException("SENHA deve ser preenchida");
            }

            try
            {
                indicator.confirmCode = Util.GenerateRamdom();
                EmailAddress emailAddress = new EmailAddress();
                emailAddress.Email = indicator.Email;
                emailAddress.Name  = indicator.Name;
                SendRegisterMailAsync(emailAddress, indicator.confirmCode).Wait();
                _repository.Create(indicator);
                IndicatorLoginDTO indicatorLogged = new IndicatorLoginDTO();
                indicatorLogged.CPF         = indicator.CPF;
                indicatorLogged.Email       = indicator.Email;
                indicatorLogged.Name        = indicator.Name;
                indicatorLogged.Status      = indicator.Status;
                indicatorLogged.IsConfirmed = indicator.IsConfirmed;
                indicatorLogged.ConfirmCode = indicator.confirmCode;
                return(indicatorLogged);
            }
            catch (Exception e)
            {
                throw new Exception($"Tipo da excessão: {e.GetType()}");
            }
        }