inclusão da api e ajustes no login

This commit is contained in:
Reginaldo
2023-05-31 17:18:33 -03:00
parent 52504d8d05
commit 9e27ea48a4
5 changed files with 255 additions and 57 deletions

View File

@@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app') project.evaluationDependsOn(':app')
} }
task clean(type: Delete) { tasks.register("clean", Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

View File

@@ -0,0 +1,42 @@
import 'package:gainer_crypto/crypto.dart';
class MainControllers{
encrypt(String senhaDigitada,String senhaUsuario) {
// Deixa e senha digitada em maiuscula
var senha = senhaDigitada.toUpperCase();
// Faz a criptografia da senha inserida
String senhaMD5 = grHashString(GRCryptoType.md5, senha);
// Retira o tipo (1, 2 ou 3) da senha do Usuário
int tipo = int.parse(senhaUsuario.substring(0, 1));
// Define a possição inicial da quebra da senha
int posicaoInicialMin = 0;
int posicaoInicialMax= 0;
int posicaoFinalMin = 0;
int posicaoFinalMax = 0;
// Pra cada tipo (1, 2 ou 3) define a posição inicial da quebra da senha
if(tipo == 1){
posicaoInicialMin = 0;
posicaoInicialMax = 16;
posicaoFinalMin = 16;
posicaoFinalMax = 32;
} else if(tipo == 2){
posicaoInicialMin = 16;
posicaoInicialMax = 32;
posicaoFinalMin = 0;
posicaoFinalMax = 16;
} else if(tipo == 3){
posicaoInicialMin = 0;
posicaoInicialMax = 1;
posicaoFinalMin = 31;
posicaoFinalMax = 32;
}
String inicio = senhaMD5.substring(posicaoInicialMin, posicaoInicialMax);
String fim = senhaMD5.substring(posicaoFinalMin, posicaoFinalMax);
// Faz a criptografia e concatena ela com sha1 e md5
String senhaCriptogradafa = tipo.toString() + '\$'+ grHashString(GRCryptoType.sha1, inicio + senha + fim);
// Retorna a senha criptografada
return senhaCriptogradafa;
}
}

View File

@@ -1,9 +1,13 @@
import 'dart:convert';
import 'package:educa_controle_acesso/screens/home_screen.dart'; import 'package:educa_controle_acesso/screens/home_screen.dart';
import 'package:educa_controle_acesso/widgets/input_text.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 'package:flutter/material.dart';
import '../controllers/main_controllers.dart';
import '../utils/colors.dart'; import '../utils/colors.dart';
import '../widgets/buttom_custom.dart'; import '../widgets/buttom_custom.dart';
import '../widgets/snackBars.dart'; import '../widgets/snackBars.dart';
import 'package:http/http.dart' as http;
class LoginScreen extends StatefulWidget { class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key); const LoginScreen({Key? key}) : super(key: key);
@@ -13,25 +17,20 @@ class LoginScreen extends StatefulWidget {
} }
class _LoginScreenState extends State<LoginScreen> { class _LoginScreenState extends State<LoginScreen> {
final inputLogin = TextEditingController(text: 'teste'); //MMATOS LOGIN IGUAL A SENHA
final inputSenha = TextEditingController(text: 'senha123'); //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(){ verificacao(){
if(inputLogin.text.isNotEmpty){ if(inputLogin.text.isNotEmpty){
if(inputSenha.text.isNotEmpty){ if(inputSenha.text.isNotEmpty){
if(inputLogin.text == 'teste@gmail.com'){ setState(() {
if(inputSenha.text == 'senha123'){ loading = true;
showSnackBar(context, 'Acesso validado', Colors.green); });
Navigator.pushReplacement( conectAPI();
context,
MaterialPageRoute(builder: (context) => HomeScreen()),
);
}else{
showSnackBar(context, 'E-mail não cadastrado e/ou senha incorreta', Colors.red);
}
}else{
showSnackBar(context, 'E-mail não cadastrado e/ou senha incorreta', Colors.red);
}
}else{ }else{
showSnackBar(context, 'Preencha sua senha', Colors.red); showSnackBar(context, 'Preencha sua senha', Colors.red);
} }
@@ -40,6 +39,43 @@ class _LoginScreenState extends State<LoginScreen> {
} }
} }
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -55,7 +91,7 @@ class _LoginScreenState extends State<LoginScreen> {
Container( Container(
child: Image.asset("assets/images/logoEduca.png",width:width * 0.15,height: height * 0.12) child: Image.asset("assets/images/logoEduca.png",width:width * 0.15,height: height * 0.12)
), ),
Container( loading?Container():Container(
width: width>900? width * 0.18:width*0.5, width: width>900? width * 0.18:width*0.5,
child: InputText( child: InputText(
inputFormatters: [], inputFormatters: [],
@@ -66,7 +102,7 @@ class _LoginScreenState extends State<LoginScreen> {
), ),
), ),
SizedBox(height: height * 0.02), SizedBox(height: height * 0.02),
Container( loading?Container():Container(
width: width>900? width * 0.18:width*0.5, width: width>900? width * 0.18:width*0.5,
child: InputText( child: InputText(
inputFormatters: [], inputFormatters: [],
@@ -78,7 +114,14 @@ class _LoginScreenState extends State<LoginScreen> {
), ),
), ),
SizedBox(height: height * 0.02), SizedBox(height: height * 0.02),
ButtonCustom( loading?Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(width: 20,),
TextCustom(text: 'Validando Acesso...')
],
):ButtonCustom(
widthCustom: 0.1, widthCustom: 0.1,
heightCustom: 0.07, heightCustom: 0.07,
text: "Entrar", text: "Entrar",

View File

@@ -1,60 +1,108 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
args:
dependency: transitive
description:
name: args
sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a
url: "https://pub.dev"
source: hosted
version: "2.4.1"
asn1lib:
dependency: transitive
description:
name: asn1lib
sha256: ab96a1cb3beeccf8145c52e449233fe68364c9641623acd3adad66f8184f1039
url: "https://pub.dev"
source: hosted
version: "1.4.0"
async: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.dartlang.org" sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted source: hosted
version: "2.9.0" version: "2.11.0"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
brasil_fields: brasil_fields:
dependency: "direct main" dependency: "direct main"
description: description:
name: brasil_fields name: brasil_fields
url: "https://pub.dartlang.org" sha256: "182e8469165785de8e93d810c8818ecddb7a6651d3b49c21d6ff3e31eeb38b78"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.12.0" version: "1.12.0"
characters: characters:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
url: "https://pub.dartlang.org" sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.1" version: "1.3.0"
clock: clock:
dependency: transitive dependency: transitive
description: description:
name: clock name: clock
url: "https://pub.dartlang.org" sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted source: hosted
version: "1.1.1" version: "1.1.1"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.16.0" version: "1.17.1"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
name: cupertino_icons name: cupertino_icons
url: "https://pub.dartlang.org" sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
encrypt:
dependency: transitive
description:
name: encrypt
sha256: "4fd4e4fdc21b9d7d4141823e1e6515cd94e7b8d84749504c232999fba25d9bbb"
url: "https://pub.dev"
source: hosted
version: "5.0.1"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
flutter: flutter:
@@ -66,7 +114,8 @@ packages:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: flutter_lints name: flutter_lints
url: "https://pub.dartlang.org" sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
flutter_test: flutter_test:
@@ -74,55 +123,102 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
gainer_crypto:
dependency: "direct main"
description:
name: gainer_crypto
sha256: "252b371d61dd7736494e740c3c432b62cefadf8416d8899cdb6d42491ceda6c0"
url: "https://pub.dev"
source: hosted
version: "0.0.6"
get: get:
dependency: "direct main" dependency: "direct main"
description: description:
name: get name: get
url: "https://pub.dartlang.org" sha256: "2ba20a47c8f1f233bed775ba2dd0d3ac97b4cf32fc17731b3dfc672b06b0e92a"
url: "https://pub.dev"
source: hosted source: hosted
version: "4.6.5" version: "4.6.5"
http:
dependency: "direct dev"
description:
name: http
sha256: "4c3f04bfb64d3efd508d06b41b825542f08122d30bda4933fb95c069d22a4fa3"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
intl: intl:
dependency: "direct main" dependency: "direct main"
description: description:
name: intl name: intl
url: "https://pub.dartlang.org" sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted source: hosted
version: "0.18.1" version: "0.18.1"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints: lints:
dependency: transitive dependency: transitive
description: description:
name: lints name: lints
url: "https://pub.dartlang.org" sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.dartlang.org" sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.12" version: "0.12.15"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted source: hosted
version: "0.1.5" version: "0.2.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.dartlang.org" sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.8.0" version: "1.9.1"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.dartlang.org" sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.8.2" version: "1.8.3"
pointycastle:
dependency: transitive
description:
name: pointycastle
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c"
url: "https://pub.dev"
source: hosted
version: "3.7.3"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@@ -132,50 +228,65 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: source_span name: source_span
url: "https://pub.dartlang.org" sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.0" version: "1.9.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.11.0"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.dartlang.org" sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.dartlang.org" sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted source: hosted
version: "1.1.1" version: "1.2.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
url: "https://pub.dev"
source: hosted source: hosted
version: "0.4.12" version: "0.5.1"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.2" version: "2.1.4"
sdks: sdks:
dart: ">=2.18.6 <3.0.0" dart: ">=3.0.0 <4.0.0"

View File

@@ -11,6 +11,7 @@ dependencies:
sdk: flutter sdk: flutter
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
gainer_crypto: ^0.0.6
brasil_fields: brasil_fields:
get: get:
intl: intl:
@@ -20,6 +21,7 @@ dev_dependencies:
sdk: flutter sdk: flutter
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
http:
flutter: flutter: