|
@@ -1,5 +1,5 @@
|
|
import 'dart:convert';
|
|
import 'dart:convert';
|
|
-import 'package:crab_ui/configManager.dart';
|
|
|
|
|
|
+import 'package:crab_ui/home_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
// import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
|
|
// import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/http.dart' as http;
|
|
@@ -119,6 +119,12 @@ class _LoginPageState extends State<LoginPage> {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Future<void> login() async {
|
|
|
|
+ bool result = await _handleLogin();
|
|
|
|
+ if (result) {
|
|
|
|
+ Navigator.pushReplacementNamed(context, '/home');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// Future<bool> _checkConfiguration() async {
|
|
// Future<bool> _checkConfiguration() async {
|
|
// return false;
|
|
// return false;
|
|
// }
|
|
// }
|
|
@@ -138,7 +144,7 @@ class _LoginPageState extends State<LoginPage> {
|
|
// }
|
|
// }
|
|
|
|
|
|
// Function to handle login action
|
|
// Function to handle login action
|
|
- Future<void> _handleLogin() async {
|
|
|
|
|
|
+ Future<bool> _handleLogin() async {
|
|
if (_formKey.currentState!.validate()) {
|
|
if (_formKey.currentState!.validate()) {
|
|
// Perform login action (e.g., authenticate with backend)
|
|
// Perform login action (e.g., authenticate with backend)
|
|
String ip = _ipController.text;
|
|
String ip = _ipController.text;
|
|
@@ -152,10 +158,10 @@ class _LoginPageState extends State<LoginPage> {
|
|
print(ip);
|
|
print(ip);
|
|
print(port);
|
|
print(port);
|
|
|
|
|
|
- final String baseUrl = "http://127.0.0.1:5000";
|
|
|
|
|
|
+ String baseUrl = "http://127.0.0.1:5000";
|
|
|
|
|
|
try {
|
|
try {
|
|
- final response = await http.get(Uri.parse('${baseUrl}/read-config'));
|
|
|
|
|
|
+ final response = await http.get(Uri.parse('$baseUrl/read-config'));
|
|
print(response.statusCode);
|
|
print(response.statusCode);
|
|
print(response.body);
|
|
print(response.body);
|
|
if (response.statusCode == 200) {
|
|
if (response.statusCode == 200) {
|
|
@@ -165,6 +171,7 @@ class _LoginPageState extends State<LoginPage> {
|
|
} catch (e) {
|
|
} catch (e) {
|
|
print("caught in catch");
|
|
print("caught in catch");
|
|
print(e);
|
|
print(e);
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
Map<String, dynamic> updates = {
|
|
Map<String, dynamic> updates = {
|
|
"username": email,
|
|
"username": email,
|
|
@@ -181,8 +188,35 @@ class _LoginPageState extends State<LoginPage> {
|
|
print("sending");
|
|
print("sending");
|
|
} catch (e) {
|
|
} catch (e) {
|
|
print(e);
|
|
print(e);
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ try {
|
|
|
|
+ // String status = await http.post(Uri.parse(''))
|
|
|
|
+ var url_log = Uri.http('127.0.0.1:3001', 'log_in');
|
|
|
|
+ Map<String, dynamic> filteredData = {
|
|
|
|
+ 'email': updates['username'],
|
|
|
|
+ 'password': updates['password']
|
|
|
|
+ };
|
|
|
|
+ print(filteredData);
|
|
|
|
+ var status = await http.post(
|
|
|
|
+ url_log,
|
|
|
|
+ headers: {
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
+ },
|
|
|
|
+ body: jsonEncode(filteredData),
|
|
|
|
+ );
|
|
|
|
+ if (status.statusCode == 200) {
|
|
|
|
+ print('response status ${status.body}');
|
|
|
|
+ if (status.body == "Successful log in") {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ print(e);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ print("after");
|
|
|
|
+ return false;
|
|
// final content = await _authService.readConfFile();
|
|
// final content = await _authService.readConfFile();
|
|
// final config = await _authService.parseConfFile(content);
|
|
// final config = await _authService.parseConfFile(content);
|
|
// print("BASE URL ${config["base_url"]}");
|
|
// print("BASE URL ${config["base_url"]}");
|
|
@@ -195,6 +229,7 @@ class _LoginPageState extends State<LoginPage> {
|
|
// _emailController.clear();
|
|
// _emailController.clear();
|
|
// _passwordController.clear();
|
|
// _passwordController.clear();
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -322,7 +357,7 @@ class _LoginPageState extends State<LoginPage> {
|
|
SizedBox(
|
|
SizedBox(
|
|
width: 200,
|
|
width: 200,
|
|
child: ElevatedButton(
|
|
child: ElevatedButton(
|
|
- onPressed: _handleLogin,
|
|
|
|
|
|
+ onPressed: login,
|
|
child: const Text('Login'),
|
|
child: const Text('Login'),
|
|
),
|
|
),
|
|
),
|
|
),
|