253 lines
8.7 KiB
Dart
253 lines
8.7 KiB
Dart
import 'dart:convert';
|
|
import 'package:educa_controle_acesso/utils/cidades_db.dart';
|
|
import 'package:educa_controle_acesso/widgets/input_text.dart';
|
|
import 'package:educa_controle_acesso/widgets/text_custom.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../controllers/main_controllers.dart';
|
|
import '../utils/colors.dart';
|
|
import '../utils/fixos.dart';
|
|
import '../widgets/buttom_custom.dart';
|
|
import '../widgets/snackBars.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:universal_html/html.dart' as html;
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
String cidade;
|
|
LoginScreen({required this.cidade});
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
//ADMIN
|
|
//las1594@@
|
|
//SENHAS CRIPTOGRAFADAS PORQUE FORMA ALTERADAS, SENHAS NOVAS USUÁRIO E SENHA SÃO IGUAIS
|
|
//ibueno
|
|
// final inputLogin = TextEditingController(text: 'admin');
|
|
// final inputSenha = TextEditingController(text: 'las1594@@');
|
|
// final inputCodigo = TextEditingController(text: 'e003');
|
|
final inputLogin = TextEditingController();
|
|
final inputSenha = TextEditingController();
|
|
final inputCodigo = TextEditingController();
|
|
bool carregando = false;
|
|
List listCodigo = [];
|
|
String urlAPI = 'https://homol-controle-educa-api.rkmsistemas.com.br';
|
|
int contLogo = 0;
|
|
String cidade = '';
|
|
|
|
carregarLista(){
|
|
for(int i=0;Cidades().listCidades.length>i;i++){
|
|
listCodigo.add(Cidades().listCidades[i].cidadeQuery);
|
|
}
|
|
}
|
|
|
|
verificacao(){
|
|
if(inputLogin.text.isNotEmpty){
|
|
if(inputSenha.text.isNotEmpty){
|
|
if(cidade!=''){
|
|
if(listCodigo.contains(cidade.toLowerCase())){
|
|
print('baseParam');
|
|
print(cidade);
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
if(inputLogin.text.toUpperCase() == 'ADMIN'){
|
|
conectAPI();
|
|
}else{
|
|
getAcessosMariaDB();
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Base não cadastrada', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha o cidade para avançar', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha seu Login', Colors.red);
|
|
}
|
|
}
|
|
|
|
getAcessosMariaDB()async{
|
|
final url = '$urlAPI/acesso_maria?LOGIN=${inputLogin.text.toUpperCase()}&CIDADE=${cidade.toUpperCase()}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
print(map);
|
|
List list = map;
|
|
if(list.length != 0 ){
|
|
for(int i=0;list.length>i;i++){
|
|
if(list[i]['ID_USUARIO']==inputLogin.text.toUpperCase() &&list[i]['CONDICAO']=='1'){
|
|
conectAPI();
|
|
}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);
|
|
}
|
|
}
|
|
|
|
conectAPI()async{
|
|
|
|
final url = '$urlAPI/logincontrole?NO_USERNAME=${inputLogin.text.toUpperCase()}&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']==inputLogin.text.toUpperCase() && map['SENHA']==inputSenha.text.toUpperCase()){
|
|
showSnackBar(context, 'Acesso validado', Colors.green);
|
|
List dados = [cidade.toUpperCase(),inputLogin.text,urlAPI];
|
|
Navigator.pushNamed(context, '/home',arguments: dados);
|
|
}else{
|
|
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']){
|
|
showSnackBar(context, 'Acesso validado', Colors.green);
|
|
List dados = [cidade.toUpperCase(),inputLogin.text,urlAPI];
|
|
Navigator.pushNamed(context, '/home',arguments: dados);
|
|
}else{
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red);
|
|
}
|
|
}
|
|
}
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
carregarLista();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
double height = MediaQuery.of(context).size.height;
|
|
double width = MediaQuery.of(context).size.width;
|
|
|
|
Uri uri = Uri.parse(html.window.location.href);
|
|
cidade = uri.queryParameters['cidade']!;
|
|
print(cidade);
|
|
|
|
return Scaffold(
|
|
backgroundColor: PaletteColors.white,
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Spacer(),
|
|
GestureDetector(
|
|
onTap: carregando?null:()=>setState((){
|
|
contLogo++;
|
|
if(contLogo<5){
|
|
urlAPI = Fixos.AMB_HOMO;
|
|
}else{
|
|
contLogo=0;
|
|
urlAPI = Fixos.AMB_DEV;
|
|
}
|
|
// 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/logoEduca.png",width:width * 0.15,height: height * 0.12)
|
|
),
|
|
),
|
|
urlAPI==Fixos.AMB_DEV?Container(
|
|
child: Image.asset("assets/images/desenvolvimento.png",width:width * 0.15,height: height * 0.12)
|
|
):Container(),
|
|
urlAPI==Fixos.AMB_HOMO?Container(
|
|
child: Image.asset("assets/images/homologacao.png",width:width * 0.15,height: height * 0.12)
|
|
):Container(),
|
|
carregando?Container():Container(
|
|
width: width>900? width * 0.18:width*0.5,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
controller: inputLogin,
|
|
title: 'LOGIN',
|
|
width: width>900? width * 0.18:width*0.5,
|
|
colorBorder: PaletteColors.white,
|
|
),
|
|
),
|
|
SizedBox(height: height * 0.02),
|
|
carregando?Container():Container(
|
|
width: width>900? width * 0.18:width*0.5,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
controller: inputSenha,
|
|
title: 'SENHA',
|
|
obscure: true,
|
|
width: width>900? width * 0.18:width*0.5,
|
|
colorBorder: PaletteColors.white,
|
|
),
|
|
),
|
|
SizedBox(height: height * 0.02),
|
|
// carregando?Container():Container(
|
|
// width: width>900? width * 0.18:width*0.5,
|
|
// child: InputText(
|
|
// inputFormatters: [],
|
|
// controller: inputCodigo,
|
|
// title: 'CÓDIGO',
|
|
// width: width>900? width * 0.18:width*0.5,
|
|
// colorBorder: PaletteColors.white,
|
|
// ),
|
|
// ),
|
|
// SizedBox(height: height * 0.02),
|
|
carregando?Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(),
|
|
SizedBox(width: 20,),
|
|
TextCustom(text: 'VALIDANDO ACESSO...')
|
|
],
|
|
):ButtonCustom(
|
|
widthCustom: 0.1,
|
|
heightCustom: 0.07,
|
|
text: "ENTRAR",
|
|
fontSize: 14.0,
|
|
colorText: PaletteColors.white,
|
|
colorButton: PaletteColors.primaryColor,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
onPressed: ()=>verificacao(),
|
|
),
|
|
Spacer(),
|
|
Row(
|
|
children: [
|
|
Spacer(),
|
|
TextCustom(text: 'versão 1.0'),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
|