142 lines
4.8 KiB
Dart
142 lines
4.8 KiB
Dart
import 'dart:convert';
|
|
import 'package:educa_controle_acesso/screens/home_screen.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> {
|
|
//MMATOS LOGIN IGUAL A SENHA
|
|
//AMENEZES LOGIN DIFERENTE DA SENHA
|
|
//SENHAS CRIPTOGRAFADAS PORQUE FORMA ALTERADAS, SENHAS NOVAS USUÁRIO E SENHA SÃO IGUAIS
|
|
final inputLogin = TextEditingController(text: 'mmatos');
|
|
final inputSenha = TextEditingController(text: 'mmatos');
|
|
bool loading = false;
|
|
|
|
verificacao(){
|
|
if(inputLogin.text.isNotEmpty){
|
|
if(inputSenha.text.isNotEmpty){
|
|
setState(() {
|
|
loading = true;
|
|
});
|
|
conectAPI();
|
|
}else{
|
|
showSnackBar(context, 'Preencha sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha seu e-mail', Colors.red);
|
|
}
|
|
}
|
|
|
|
conectAPI()async{
|
|
final url = 'http://192.168.18.2/projeto/api_educa/index.php/?NO_USERNAME=${inputLogin.text.toUpperCase()}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
print(map);
|
|
if(map==false){
|
|
showSnackBar(context, 'E-mail não cadastrado e/ou senha incorreta', 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);
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => HomeScreen()),
|
|
);
|
|
}else{
|
|
showSnackBar(context, 'E-mail não cadastrado e/ou senha incorreta', Colors.red);
|
|
}
|
|
}else{
|
|
print(MainControllers().encrypt(inputSenha.text,map['SENHA']));
|
|
if(MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']){
|
|
showSnackBar(context, 'Acesso validado', Colors.green);
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => HomeScreen()),
|
|
);
|
|
}else{
|
|
showSnackBar(context, 'E-mail não cadastrado e/ou senha incorreta', Colors.red);
|
|
}
|
|
// MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']
|
|
}
|
|
}
|
|
setState(() {
|
|
loading = false;
|
|
});
|
|
}
|
|
|
|
@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)
|
|
),
|
|
loading?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),
|
|
loading?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),
|
|
loading?Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(),
|
|
SizedBox(width: 20,),
|
|
TextCustom(text: 'Validando Acesso...')
|
|
],
|
|
):ButtonCustom(
|
|
widthCustom: 0.1,
|
|
heightCustom: 0.07,
|
|
text: "Entrar",
|
|
size: 14.0,
|
|
colorText: PaletteColors.white,
|
|
colorButton: PaletteColors.primaryColor,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
onPressed: ()=>verificacao(),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
|