233 lines
7.4 KiB
Dart
233 lines
7.4 KiB
Dart
import 'dart:math';
|
|
import 'package:gainer_crypto/crypto.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:rkm/service/db/db_querys.dart';
|
|
|
|
class MainControllers{
|
|
encrypt(String senhaDigitada,String senhaUsuario) {
|
|
// Deixa e senha digitada em maiuscula
|
|
var senha = senhaDigitada.toUpperCase();
|
|
// Faz a criptografia da senha inserida
|
|
String senhaMD5 = grHashString(GRCryptoType.md5, senha);
|
|
print('senhaMD5');
|
|
print(senhaMD5);
|
|
// Retira o tipo (1, 2 ou 3) da senha do Usuário
|
|
int tipo = int.parse(senhaUsuario.substring(0, 1));
|
|
|
|
print('tipo $tipo');
|
|
// Define a possição inicial da quebra da senha
|
|
int posicaoInicialMin = 0;
|
|
int posicaoInicialMax= 0;
|
|
int posicaoFinalMin = 0;
|
|
int posicaoFinalMax = 0;
|
|
// Pra cada tipo (1, 2 ou 3) define a posição inicial da quebra da senha
|
|
if(tipo == 1){
|
|
posicaoInicialMin = 0;
|
|
posicaoInicialMax = 16;
|
|
posicaoFinalMin = 16;
|
|
posicaoFinalMax = 32;
|
|
} else if(tipo == 2){
|
|
posicaoInicialMin = 16;
|
|
posicaoInicialMax = 32;
|
|
posicaoFinalMin = 0;
|
|
posicaoFinalMax = 16;
|
|
} else if(tipo == 3){
|
|
posicaoInicialMin = 0;
|
|
posicaoInicialMax = 1;
|
|
posicaoFinalMin = 31;
|
|
posicaoFinalMax = 32;
|
|
}
|
|
|
|
String inicio = senhaMD5.substring(posicaoInicialMin, posicaoInicialMax);
|
|
print('inicio');
|
|
print(inicio);
|
|
String fim = senhaMD5.substring(posicaoFinalMin, posicaoFinalMax);
|
|
|
|
print('fim');
|
|
print(fim);
|
|
|
|
// Faz a criptografia e concatena ela com sha1 e md5
|
|
String senhaCriptogradafa = tipo.toString() + '\$'+ grHashString(GRCryptoType.sha1, inicio + senha + fim);
|
|
print('senhaCriptogradafa');
|
|
print(senhaCriptogradafa);
|
|
// Retorna a senha criptografada
|
|
return senhaCriptogradafa;
|
|
}
|
|
validaCNS(String cns,bool editing)async{
|
|
//valido provisório 783107557570002
|
|
//cns valido def 187455333020009
|
|
String response = 'CNS inválido';
|
|
String type = cns.substring(0,1);
|
|
if(type == '7'|| type =='8' || type == '9'){
|
|
response = await validaCNSProv(cns,editing);
|
|
}else{
|
|
response = validaCNSDef(cns,editing);
|
|
}
|
|
return response;
|
|
}
|
|
validaCNSProv(String vlrCNS,bool editing)async{
|
|
int resto;
|
|
int soma;
|
|
if(vlrCNS.length == 15){
|
|
// print('pis');
|
|
// print(vlrCNS);
|
|
soma = ((int.parse(vlrCNS.substring( 0, 1))) * 15)
|
|
+ ((int.parse(vlrCNS.substring( 1, 2))) * 14)
|
|
+ ((int.parse(vlrCNS.substring( 2, 3))) * 13)
|
|
+ ((int.parse(vlrCNS.substring( 3, 4))) * 12)
|
|
+ ((int.parse(vlrCNS.substring( 4, 5))) * 11)
|
|
+ ((int.parse(vlrCNS.substring( 5, 6))) * 10)
|
|
+ ((int.parse(vlrCNS.substring( 6, 7))) * 9)
|
|
+ ((int.parse(vlrCNS.substring( 7, 8))) * 8)
|
|
+ ((int.parse(vlrCNS.substring( 8, 9))) * 7)
|
|
+ ((int.parse(vlrCNS.substring( 9,10))) * 6)
|
|
+ ((int.parse(vlrCNS.substring(10,11))) * 5)
|
|
+ ((int.parse(vlrCNS.substring(11,12))) * 4)
|
|
+ ((int.parse(vlrCNS.substring(12,13))) * 3)
|
|
+ ((int.parse(vlrCNS.substring(13,14))) * 2)
|
|
+ ((int.parse(vlrCNS.substring(14,15))) * 1);
|
|
|
|
resto = soma % 11;
|
|
// print('soma');
|
|
// print(soma);
|
|
// print('resto');
|
|
// print(resto);
|
|
if (resto == 0)
|
|
{
|
|
// CNS provisório válido
|
|
List result = editing?[]:await DBQuerys().duplicidadeCNS(vlrCNS);
|
|
if(result.length==0){
|
|
return 'ok';
|
|
}else{
|
|
return 'CNS duplicado';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// CNS provisório inválido
|
|
return 'CNS provisório inválido';
|
|
}
|
|
}else{
|
|
if(vlrCNS.length< 15){
|
|
return 'CNS inválido! Faltando números';
|
|
}else{
|
|
return 'CNS inválido! Sobrando números';
|
|
}
|
|
}
|
|
}
|
|
validaCNSDef(String vlrCNS,bool editing){
|
|
int soma = 0;
|
|
int resto = 0;
|
|
int dv = 0;
|
|
String pis = '';
|
|
String resultado = '';
|
|
|
|
if(vlrCNS.length == 15){
|
|
pis = vlrCNS.substring(0,11);
|
|
soma = (int.parse(pis.substring(0,1)) * 15) +
|
|
((int.parse(pis.substring(1,2))) * 14) +
|
|
((int.parse(pis.substring(2,3))) * 13) +
|
|
((int.parse(pis.substring(3,4))) * 12) +
|
|
((int.parse(pis.substring(4,5))) * 11) +
|
|
((int.parse(pis.substring(5,6))) * 10) +
|
|
((int.parse(pis.substring(6,7))) * 9) +
|
|
((int.parse(pis.substring(7,8))) * 8) +
|
|
((int.parse(pis.substring(8,9))) * 7) +
|
|
((int.parse(pis.substring(9,10))) * 6) +
|
|
((int.parse(pis.substring(10,11))) * 5);
|
|
resto = soma % 11;
|
|
dv = 11 - resto;
|
|
if (dv == 11) {
|
|
dv = 0;
|
|
}
|
|
if (dv == 10) {
|
|
soma = (((int.parse(pis.substring(0,1))) * 15) +
|
|
((int.parse(pis.substring(1,2))) * 14) +
|
|
((int.parse(pis.substring(2,3))) * 13) +
|
|
((int.parse(pis.substring(3,4))) * 12) +
|
|
((int.parse(pis.substring(4,5))) * 11) +
|
|
((int.parse(pis.substring(5,6))) * 10) +
|
|
((int.parse(pis.substring(6,7))) * 9) +
|
|
((int.parse(pis.substring(7,8))) * 8) +
|
|
((int.parse(pis.substring(8,9))) * 7) +
|
|
((int.parse(pis.substring(9,10))) * 6) +
|
|
((int.parse(pis.substring(10,11))) * 5) + 2);
|
|
resto = soma % 11;
|
|
dv = 11 - resto;
|
|
resultado = pis + "001" + dv.toString();
|
|
} else {
|
|
resultado = pis + "000" + dv.toString();
|
|
}
|
|
if (vlrCNS != resultado) {
|
|
// CNS inválido
|
|
return 'CNS definitivo inválido';
|
|
} else {
|
|
// CNS válido
|
|
String result = editing?[]: DBQuerys().duplicidadeCNS(vlrCNS);
|
|
if(result==''){
|
|
return 'ok';
|
|
}else{
|
|
return 'CNS duplicado"';
|
|
}
|
|
}
|
|
}else{
|
|
if(vlrCNS.length< 15){
|
|
return 'CNS inválido! Faltando números';
|
|
}else{
|
|
return 'CNS inválido! Sobrando números';
|
|
}
|
|
}
|
|
}
|
|
validaCPF(String cpf,bool editing)async{
|
|
// 60352523620 CPF VÁLIDO
|
|
if(GetUtils.isCpf(cpf)){
|
|
if(editing){
|
|
return 'ok';
|
|
}else{
|
|
List result = await DBQuerys().duplicidadeCPF(cpf);
|
|
// print(cpf);
|
|
if(result.length==0){
|
|
return 'ok';
|
|
}else{
|
|
return 'CPF duplicado';
|
|
}
|
|
}
|
|
}else{
|
|
return 'CPF inválido';
|
|
}
|
|
}
|
|
gerarCDUsuarioSus(){
|
|
String mkTime = ((DateTime.now().millisecond)).toString();
|
|
String seqID = ((Random().nextInt(10)*100).floor() + ((Random().nextInt(10) * 5).floor() + 1)).toString() + '00000';
|
|
String cdUsuarioSUS = (grHashString(GRCryptoType.md5, mkTime) + seqID).toUpperCase();
|
|
var codSize = cdUsuarioSUS.length;
|
|
cdUsuarioSUS = cdUsuarioSUS.substring(0,32);
|
|
'cod sus recuperado api';
|
|
// 571A22D79C24526537C7E4CE8C0D4046
|
|
'cod gerado para teste';
|
|
// CA8155F4D27F205953F9D3D7974BDD70
|
|
// 571A22D79C24526537C7E4CE8C0D4046
|
|
// C73F93513A57571D2C7B6384A34AD22F
|
|
|
|
return cdUsuarioSUS;
|
|
}
|
|
replaceDefaul(String text){
|
|
String newText = text.toUpperCase()
|
|
.replaceAll('Ã', 'A')
|
|
.replaceAll('Á', 'A')
|
|
.replaceAll('À', 'A')
|
|
.replaceAll('Â', 'A')
|
|
.replaceAll('Ç', 'C')
|
|
.replaceAll('È', 'E')
|
|
.replaceAll('É', 'E')
|
|
.replaceAll('Ê', 'E')
|
|
.replaceAll('Í', 'I')
|
|
.replaceAll('Ô', 'O')
|
|
.replaceAll('Õ', 'O')
|
|
.replaceAll('Ó', 'O')
|
|
.replaceAll('Ú', 'U')
|
|
.replaceAll('Û', 'U')
|
|
;
|
|
return newText;
|
|
}
|
|
} |