270 lines
9.4 KiB
Dart
270 lines
9.4 KiB
Dart
import 'dart:convert';
|
|
import 'package:brasil_fields/brasil_fields.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:package_info/package_info.dart';
|
|
import 'package:rkm_educa_prof_app/telas/tela_home.dart';
|
|
import '../componentes/buttom_custom.dart';
|
|
import '../componentes/input_text.dart';
|
|
import '../componentes/snackBars.dart';
|
|
import '../controllers/main_controllers.dart';
|
|
import '../servicos/shared_preferences/shared.dart';
|
|
import '../utils/cores.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../componentes/text_custom.dart';
|
|
import '../utils/dimensoes.dart';
|
|
import '../utils/fixos.dart';
|
|
|
|
class TelaLogin extends StatefulWidget {
|
|
const TelaLogin({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<TelaLogin> createState() => _TelaLoginState();
|
|
}
|
|
|
|
class _TelaLoginState extends State<TelaLogin> {
|
|
|
|
// final inputLogin = TextEditingController(text: '402.061.058-43');
|
|
final inputLogin = TextEditingController();
|
|
final inputSenha = TextEditingController();
|
|
final inputRepetirSenha = TextEditingController();
|
|
bool carregando = false;
|
|
String tituloSenha = 'Senha';
|
|
String status = 'VALIDANDO ACESSO...';
|
|
var map;
|
|
int contLogo = 0;
|
|
String urlAPI = 'https://homol-controle-educa-api.rkmsistemas.com.br';
|
|
final PrefService _prefService = PrefService();
|
|
String _version = 'Carregando...';
|
|
String idUsuario = '';
|
|
|
|
verificacao(){
|
|
if(inputLogin.text.isNotEmpty){
|
|
if(inputSenha.text.isNotEmpty){
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
getAcessosMariaDB();
|
|
}else{
|
|
showSnackBar(context, 'Preencha sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha seu Login', Colors.red);
|
|
}
|
|
}
|
|
|
|
conectAPI(String cidade, String usuario)async{
|
|
|
|
final url = '$urlAPI/logincontrole?NO_USERNAME=${usuario}&CIDADE=${cidade.toUpperCase()}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
print(map);
|
|
if(map==false){
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red);
|
|
}else{
|
|
if(map['NO_USERNAME']==map['SENHA']){
|
|
if(map['NO_USERNAME']==usuario && map['SENHA']==inputSenha.text.toUpperCase()){
|
|
showSnackBar(context, 'Acesso validado', Colors.green);
|
|
List <String> dados = [
|
|
cidade.toUpperCase(),//0
|
|
map['NO_USUARIO_SISTEMA']??'',//1
|
|
urlAPI,//2
|
|
map['NO_FANTASIA']??'',//3
|
|
map['CD_UNIDADE'].toString()??'',//4
|
|
inputLogin.text,//5
|
|
usuario,//6
|
|
inputSenha.text,//7
|
|
map['CD_USUARIO_SISTEMA'].toString()//8
|
|
];
|
|
_prefService.createCacheLogin(dados).then((value){
|
|
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => TelaHome(dados: dados) ));
|
|
});
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red);
|
|
}
|
|
}else{
|
|
if(MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']){
|
|
print(map);
|
|
showSnackBar(context, 'Acesso validado', Colors.green);
|
|
List <String> dados = [
|
|
cidade.toUpperCase(),//0
|
|
map['NO_USUARIO_SISTEMA']??'',//1
|
|
urlAPI,//2
|
|
map['NO_FANTASIA']??'',//3
|
|
map['CD_UNIDADE'].toString()??'',//4
|
|
inputLogin.text,//5
|
|
usuario,//6
|
|
inputSenha.text,//7
|
|
map['CD_USUARIO_SISTEMA'].toString()//8
|
|
];
|
|
_prefService.createCacheLogin(dados).then((value) =>
|
|
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => TelaHome(dados: dados) )));
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
getAcessosMariaDB()async{
|
|
final url = '$urlAPI/loginprof?CPF=${inputLogin.text}';
|
|
print(url);
|
|
await http.get(Uri.parse(url)).then((response) async{
|
|
var map = await json.decode(response.body);
|
|
print(map);
|
|
if(map != false){
|
|
if(map['CPF']==inputLogin.text && map['APP_PROFESSORES']=='1'){
|
|
print('api foi');
|
|
idUsuario = map['ID_USUARIO'];
|
|
conectAPI(map['CIDADE'],map['ID_USUARIO']);
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
showSnackBar(context, 'Login seu acesso não está liberado!', Colors.red);
|
|
}
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> _getAppVersion() async {
|
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
|
String version = packageInfo.version;
|
|
setState(() {
|
|
_version = version;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_getAppVersion();
|
|
_prefService.readCacheLogin().then((login){
|
|
if(login!=null){
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
print(login);
|
|
inputLogin.text = login[5];
|
|
inputSenha.text = login[7];
|
|
if(login[0]!='' && login[6]!=''){
|
|
conectAPI(login[0],login[6]);
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: PaletaCores.branco,
|
|
body: Container(
|
|
padding: EdgeInsets.all(Dimensoes.width*0.15),
|
|
width: Dimensoes.width,
|
|
height: Dimensoes.height,
|
|
alignment: Alignment.center,
|
|
child: ListView(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: carregando?null:()=>setState((){
|
|
contLogo++;
|
|
if(contLogo<5){
|
|
urlAPI = Fixos.LINK_API_HOMOL;
|
|
}else{
|
|
contLogo=0;
|
|
urlAPI = Fixos.LINK_API_LOCAL;
|
|
}
|
|
// if(contLogo>=5 && contLogo<=10){
|
|
// urlAPI = Fixos.AMB_HOMO;
|
|
// }
|
|
// if(contLogo>10){
|
|
// urlAPI = Fixos.AMB_DEV;
|
|
// if(contLogo==15){
|
|
// contLogo=0;
|
|
// urlAPI = Fixos.AMB_PROD;
|
|
// }
|
|
// }
|
|
// print(contLogo);
|
|
// print(urlAPI);
|
|
}),
|
|
child: Container(
|
|
child: Image.asset("assets/images/rkmprof.png",width:Dimensoes.width * 0.35,height: Dimensoes.height * 0.10)
|
|
),
|
|
),
|
|
urlAPI==Fixos.LINK_API_LOCAL?Container(
|
|
child: Image.asset("assets/images/desenvolvimento.png",width:Dimensoes.width * 0.5,height: Dimensoes.height * 0.12)
|
|
):Container(),
|
|
urlAPI==Fixos.LINK_API_HOMOL?Container(
|
|
child: Image.asset("assets/images/homologacao.png",width:Dimensoes.width * 0.5,height: Dimensoes.height * 0.12)
|
|
):Container(),
|
|
carregando?Container():Container(
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
child: InputText(
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
CpfInputFormatter(),
|
|
],
|
|
textInputType: TextInputType.text,
|
|
controller: inputLogin,
|
|
title: 'CPF',
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
colorBorder: PaletaCores.branco,
|
|
),
|
|
),
|
|
carregando?Container():Container(
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
controller: inputSenha,
|
|
title: tituloSenha,
|
|
obscure: true,
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
colorBorder: PaletaCores.branco,
|
|
),
|
|
),
|
|
SizedBox(height: Dimensoes.height * 0.02),
|
|
SizedBox(height: Dimensoes.height * 0.02),
|
|
carregando?Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(color: PaletaCores.cinzaClaro,),
|
|
SizedBox(width: 20,),
|
|
TextCustom(text: status,maxLines: 1,size: 12.0,)
|
|
],
|
|
):ButtonCustom(
|
|
widthCustom: 0.7,
|
|
heightCustom: 0.07,
|
|
text: "Entrar",
|
|
fontsize: 14.0,
|
|
colorText: PaletaCores.branco,
|
|
colorButton: PaletaCores.corPrimaria,
|
|
colorBorder: PaletaCores.corPrimaria,
|
|
onPressed: ()=>verificacao(),
|
|
),
|
|
carregando?Container():Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 20.0),
|
|
child: Center(child: Text('Versão: $_version')),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|