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); }
public UserLoginDTO Login(string cpf, string password) { UserUtil Util = new UserService(); 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}"); } User user = _repository.GetUserLogin(cpf, password); if (Util.ObjectIsNull(user)) { throw new NotFoundException("CPF ou SENHA inválidos"); } switch (user.UserEnum) { case Enums.UserEnum.INACTIVE: throw new BadRequestException("Este usuário está inativo :c"); case Enums.UserEnum.BLOCKED: throw new BadRequestException("Este usuário está bloqueado :c"); } // Gera o Token var token = TokenService.GenerateTokenUserCompany(user); UserLoginDTO userLogged = new UserLoginDTO(); userLogged.CPF = user.CPF; userLogged.Email = user.Email; userLogged.Name = user.Name; userLogged.UserCompanies = user.UserCompanies; userLogged.UserEnum = user.UserEnum; userLogged.UserRole = user.UserRole; userLogged.Token = token; return(userLogged); }
public async Task <bool> forgotPassUser(String cpf) { CpfValidate cpfValidate = new CpfValidate(); if (String.IsNullOrEmpty(cpf)) { throw new BadRequestException("CPF em branco!"); } if (!cpfValidate.ValidaCPF(cpf)) { throw new BadRequestException("CPF inválido!"); } Indicator user = new Indicator(); try { user = _repository.GetIndicatorByCPF(cpf); } catch (Exception e) { throw new Exception("Algo deu errado: " + e.GetType()); } if (user == null) { throw new NotFoundException("Não existe um usuário com este documento!"); } bool res = await _sendForgotPassEmail.SendMessageAsync(new EmailAddress(user.Email, user.Name), "Sua senha é: " + user.Password); return(res); }
public Indication InsertNew(Indication indication) { IndicationUtil util = new IndicationService(); if (util.ObjectIsNull(indication)) { throw new BadRequestException($"Indicação não pode estar vazia!"); } if (util.StringIsNull(indication.DocumentType.ToString())) { throw new BadRequestException($"Preencha o tipo da indicação!"); } if (util.StringIsNull(indication.Document)) { throw new BadRequestException($"Documento da indicação deve estar preenchida"); } switch (indication.DocumentType) { case Enums.DocumentType.CNPJ: if (!_cnpjValidate.ValidaCNPJ(indication.Document)) { throw new BadRequestException($"Este cnpj é inválido: {indication.Document}"); } break; case Enums.DocumentType.CPF: if (!_cpfValidate.ValidaCPF(indication.Document)) { throw new BadRequestException($"Este cpf é inválido: {indication.Document}"); } break; } if (util.StringIsNull(indication.CellPhone) && util.StringIsNull(indication.Phone)) { throw new BadRequestException($"Preencha pelo menos um dos telefones!"); } if (util.StringIsNull(indication.Branch.ToString())) { throw new BadRequestException($"O ramo de atuação da indicação deve ser preenchido"); } Product product = _productRepository.getProduct(indication.ProductId); foreach (Indication i in product.Indications) { if (i.Document == indication.Document) { throw new BadRequestException($"Este produto já foi indicado para empresa: {indication.Document}"); } } try { _repository.Create(indication); return(indication); } catch (Exception e) { throw new Exception($"Algo deu errado: {e}, tente mais tarde ou entre em contato!"); } }