340 lines
13 KiB
Dart
340 lines
13 KiB
Dart
import 'dart:convert';
|
|
import 'package:brasil_fields/brasil_fields.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:rkm_educa_app/Telas/tela_situacao_escolar.dart';
|
|
import 'package:rkm_educa_app/controllers/main_controllers.dart';
|
|
import 'package:rkm_educa_app/modelos/estudante_modelo.dart';
|
|
import 'package:rkm_educa_app/telas/tela_cadastro.dart';
|
|
import 'package:rkm_educa_app/telas/tela_seleciona_filho.dart';
|
|
import 'package:rkm_educa_app/utils/dimensoes.dart';
|
|
import '../servicos/shared_preferences/shared.dart';
|
|
import '../utils/cores.dart';
|
|
import '../componentes/buttom_custom.dart';
|
|
import '../componentes/input_text.dart';
|
|
import '../componentes/snackBars.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../componentes/text_custom.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;
|
|
bool alterarSenha = false;
|
|
String tituloSenha = 'Senha';
|
|
EstudanteModelo? estudanteModelo;
|
|
String status = 'VALIDANDO ACESSO...';
|
|
var map;
|
|
int contLogo = 0;
|
|
String urlAPI = 'https://homol-controle-educa-api.rkmsistemas.com.br';
|
|
List <EstudanteModelo> umFilho = [];
|
|
|
|
verificacao(){
|
|
if(inputLogin.text.isNotEmpty){
|
|
if(inputSenha.text.isNotEmpty){
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
conectAPI(inputLogin.text.toUpperCase(),inputSenha.text.toUpperCase());
|
|
}else{
|
|
showSnackBar(context, 'Preencha sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha seu Login', Colors.red);
|
|
}
|
|
}
|
|
|
|
salvarSenha()async{
|
|
if(inputLogin.text.isNotEmpty && inputSenha.text.isNotEmpty && inputRepetirSenha.text.isNotEmpty){
|
|
if(inputLogin.text.replaceAll('-', '').replaceAll('.', '') != inputSenha.text
|
|
&& inputLogin.text.replaceAll('-', '').replaceAll('.', '') != inputRepetirSenha.text){
|
|
if(inputSenha.text == inputRepetirSenha.text){
|
|
if(inputSenha.text.length >5){
|
|
carregando = true;
|
|
alterarSenha = false;
|
|
status = 'ALTERANDO SENHA ...';
|
|
setState(() {});
|
|
final url = '$urlAPI/inserirpais';
|
|
|
|
final response = await http.post(
|
|
Uri.parse(url),
|
|
body:{
|
|
'CD_ALUNO' : map['CD_ALUNO'],
|
|
'ALUNO': map['ALUNO'],
|
|
'CPF': map['CPF'],
|
|
'NOME' : map['NOME'],
|
|
'SENHA' : inputSenha.text,
|
|
'PARENTESCO' : map['PARENTESCO'],
|
|
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
|
'CONDICAO' : 'EDITADO',
|
|
'CIDADE' : map['CIDADE']
|
|
}
|
|
);
|
|
|
|
showSnackBar(context, 'Senha Alterada com Sucesso!'.toString().toUpperCase(), Colors.green);
|
|
carregando = false;
|
|
alterarSenha = false;
|
|
inputSenha.clear();
|
|
inputRepetirSenha.clear();
|
|
tituloSenha = 'Senha';
|
|
setState(() {});
|
|
}else{
|
|
showSnackBar(context, 'Mínimo deve conter 6 caracteres', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Novas senhas não são iguais', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Nova senha não pode ser igual a anterior', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha todos os campos para avançar', Colors.red);
|
|
}
|
|
}
|
|
|
|
conectAPI(String cpf, String senha)async{
|
|
final PrefService _prefService = PrefService();
|
|
final url = '$urlAPI/loginpais?CPF=$cpf';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
map = json.decode(response.body);
|
|
print(map);
|
|
if(map==false){
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red);
|
|
}else{
|
|
if(map['CONDICAO']!='BLOQUEADO'){
|
|
if(map['CPF'].toString().replaceAll('-', '').replaceAll('.', '')!= map['SENHA']){
|
|
if(map['CPF']==cpf && map['SENHA'].toString().toUpperCase()==senha){
|
|
setState(() {
|
|
status = 'CARREGANDO ESTUDANTE(S) ...';
|
|
});
|
|
showSnackBar(context, 'Acesso validado', Colors.green);
|
|
_prefService.createCacheLogin(map['CPF'], map['SENHA']).then((value)async{
|
|
int ano = 0;
|
|
ano = await MainControllers().pegarAno(urlAPI,map['CIDADE']);
|
|
print(ano);
|
|
buscaFilhos(map['NOME'],map['PARENTESCO'],map['CIDADE'],map['CPF'].toString().replaceAll('-', '').replaceAll('.', ''),ano);
|
|
});
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
_prefService.removeCacheLogin();
|
|
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red);
|
|
}
|
|
}else{
|
|
alterarSenha = true;
|
|
carregando = false;
|
|
inputSenha.clear();
|
|
tituloSenha = 'Senha Nova';
|
|
setState(() {});
|
|
showSnackBar(context, 'Altere sua senha para continuar', Colors.red);
|
|
}
|
|
}else{
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
showSnackBar(context, 'Seu acesso não está liberado', Colors.red);
|
|
}
|
|
}
|
|
}
|
|
|
|
buscaFilhos(String nome,String parentesco,String cidade, String CPF,int anoLetivo)async{
|
|
String q = nome.replaceAll(' ', '%20').toUpperCase();
|
|
final url = '$urlAPI/buscafilhos?NOME=$q&PARENTESCO=${parentesco.replaceAll("Ã", 'A').replaceAll('ã', 'a')}&CIDADE=$cidade';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
|
|
List listAlunos = map;
|
|
// print(listAlunos);
|
|
print('listAlunos.length');
|
|
print(listAlunos.length);
|
|
setState(() {
|
|
carregando = false;
|
|
});
|
|
if(listAlunos.length!=0){
|
|
if(listAlunos.length==1){
|
|
|
|
String dataBD = listAlunos[0]['DT_NASCIMENTO'];
|
|
int dia = 00;
|
|
int mes = 00;
|
|
int ano = 0000;
|
|
int idade = 0;
|
|
if(dataBD!=''){
|
|
dia = int.parse(dataBD.substring(6,8));
|
|
mes = int.parse(dataBD.substring(4,6));
|
|
ano = int.parse(dataBD.substring(0,4));
|
|
final hoje = DateTime.now();
|
|
final nasc = DateTime.utc(ano,mes,dia);
|
|
idade = (hoje.difference(nasc).inDays/365).toInt();
|
|
}
|
|
|
|
estudanteModelo = EstudanteModelo(
|
|
NO_ALUNO: listAlunos[0]['NO_ALUNO'],
|
|
FOTO_ALUNO: '',
|
|
RA_ALUNO: listAlunos[0]['NR_RA'],
|
|
ESCOLA: listAlunos[0]['NO_FANTASIA']=='' || listAlunos[0]['NO_FANTASIA']==null?listAlunos[0]['NO_RAZAO_SOCIAL']:listAlunos[0]['NO_FANTASIA'],
|
|
IDADE_ALUNO: idade,
|
|
ANO_LETIVO: anoLetivo,
|
|
dados: listAlunos,
|
|
nroAluno: 0,
|
|
cidade: cidade,
|
|
NO_USUARIO: nome,
|
|
CD_USUARIO: CPF,
|
|
URL: urlAPI
|
|
);
|
|
umFilho.add(estudanteModelo!);
|
|
Navigator.pushReplacement(context,MaterialPageRoute(builder: (context) => TelaSituacaoEscolar(alunos: umFilho,indiceAluno: 0,)));
|
|
}else{
|
|
Navigator.pushReplacement(context,MaterialPageRoute(builder: (context) =>
|
|
TelaSelecionaFilho(listAlunos: listAlunos,cidade: cidade,CD_USUARIO: CPF,NO_USUARIO: nome,URL: urlAPI,)));
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Estudante não encontrado', Colors.red);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final PrefService _prefService = PrefService();
|
|
_prefService.readCacheLogin().then((login){
|
|
if(login!=null){
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
print(login);
|
|
conectAPI(login[0], login[1].toString().toUpperCase());
|
|
}
|
|
});
|
|
}
|
|
|
|
@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/logoEduca.png",width:Dimensoes.width * 0.4,height: Dimensoes.height * 0.12)
|
|
),
|
|
),
|
|
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.number,
|
|
controller: inputLogin,
|
|
title: 'Login',
|
|
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,
|
|
),
|
|
),
|
|
!alterarSenha?Container():Container(
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
controller: inputRepetirSenha,
|
|
title: 'Repetir Nova senha',
|
|
obscure: true,
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
colorBorder: PaletaCores.branco,
|
|
),
|
|
),
|
|
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: alterarSenha?'Alterar Senha':"Entrar",
|
|
fontsize: 14.0,
|
|
colorText: PaletaCores.branco,
|
|
colorButton: PaletaCores.corPrimaria,
|
|
colorBorder: PaletaCores.corPrimaria,
|
|
onPressed: ()=>alterarSenha?salvarSenha():verificacao(),
|
|
),
|
|
carregando?Container():GestureDetector(
|
|
onTap: ()=>Navigator.push(context, MaterialPageRoute(builder: (context)=>TelaCadastro(api: urlAPI,))),
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
padding: EdgeInsets.symmetric(vertical: 15),
|
|
width: Dimensoes.width,
|
|
child: TextCustom(text: 'Não tem cadastro? Cadastre-se!',color: PaletaCores.corPrimaria,)
|
|
),
|
|
)
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|