214 lines
7.1 KiB
Dart
214 lines
7.1 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 '../widgets/buttom_custom.dart';
|
|
import '../widgets/snackBars.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({Key? key}) : super(key: key);
|
|
|
|
@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');
|
|
bool carregando = false;
|
|
List listCodigo = [];
|
|
|
|
carregarLista(){
|
|
for(int i=0;Cidades().listCidades.length>i;i++){
|
|
listCodigo.add(Cidades().listCidades[i].codigo);
|
|
}
|
|
}
|
|
|
|
verificacao(){
|
|
if(inputLogin.text.isNotEmpty){
|
|
if(inputSenha.text.isNotEmpty){
|
|
if(inputCodigo.text.isNotEmpty){
|
|
if(listCodigo.contains(inputCodigo.text.toUpperCase())){
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
if(inputLogin.text.toUpperCase() == 'ADMIN'){
|
|
conectAPI();
|
|
}else{
|
|
getAcessosMariaDB();
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Código inválido', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha o código de acesso', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha seu Login', Colors.red);
|
|
}
|
|
}
|
|
|
|
getAcessosMariaDB()async{
|
|
String cidade = '';
|
|
for(int i =0; Cidades().listCidades.length>i;i++){
|
|
if(Cidades().listCidades[i].codigo == inputCodigo.text.toUpperCase()){
|
|
cidade = Cidades().listCidades[i].cidadeQuery.toUpperCase();
|
|
}
|
|
}
|
|
final url = 'http://192.168.18.2:8000/acesso_maria?LOGIN=${inputLogin.text.toUpperCase()}&CIDADE=$cidade';
|
|
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{
|
|
|
|
String cidade = '';
|
|
for(int i =0; Cidades().listCidades.length>i;i++){
|
|
if(Cidades().listCidades[i].codigo == inputCodigo.text.toUpperCase()){
|
|
cidade = Cidades().listCidades[i].cidadeQuery.toUpperCase();
|
|
}
|
|
}
|
|
|
|
final url = 'http://192.168.18.2:8000/logincontrole?NO_USERNAME=${inputLogin.text.toUpperCase()}&CIDADE=$cidade';
|
|
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,inputLogin.text];
|
|
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,inputLogin.text];
|
|
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;
|
|
|
|
return Scaffold(
|
|
backgroundColor: PaletteColors.white,
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
child: Image.asset("assets/images/logoEduca.png",width:width * 0.15,height: height * 0.12)
|
|
),
|
|
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 * 0.18,
|
|
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 * 0.18,
|
|
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(),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
|