login #1
@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:crab_ui/api_service.dart';
|
||||||
import 'package:crab_ui/home_page.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';
|
||||||
@ -9,15 +10,29 @@ import 'package:flutter/services.dart' show rootBundle;
|
|||||||
class AuthService {
|
class AuthService {
|
||||||
Future<bool> isUserLoggedIn() async {
|
Future<bool> isUserLoggedIn() async {
|
||||||
try {
|
try {
|
||||||
var url = Uri.http('0.0.0.0:3001', 'is_logged_in');
|
final response =
|
||||||
var response = await http.get(url);
|
await http.get(Uri.parse('http://localhost:6823/read-config'));
|
||||||
|
print(response.statusCode);
|
||||||
print(response.body);
|
print(response.body);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
print('all good in the east!');
|
final data = jsonDecode(response.body);
|
||||||
String jsonOuter = jsonDecode(response.body);
|
// return data['config'];
|
||||||
Map<String, dynamic> json = jsonDecode(jsonOuter);
|
try {
|
||||||
// print(json["is_logged_in"]);
|
var url = Uri.http('${data['ip']}:${data['port']}', 'is_logged_in');
|
||||||
return json["is_logged_in"];
|
var response = await http.get(url);
|
||||||
|
print(response.body);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
print('all good in the east!');
|
||||||
|
String jsonOuter = jsonDecode(response.body);
|
||||||
|
Map<String, dynamic> json = jsonDecode(jsonOuter);
|
||||||
|
// print(json["is_logged_in"]);
|
||||||
|
ApiService.ip = data['ip'];
|
||||||
|
ApiService.port = data['port'];
|
||||||
|
return json["is_logged_in"];
|
||||||
|
}
|
||||||
|
} catch (er) {
|
||||||
|
print(er);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
@ -162,7 +177,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
print("baseurl " + baseUrl);
|
print("baseurl " + baseUrl);
|
||||||
print(baseUrl);
|
print(baseUrl);
|
||||||
try {
|
try {
|
||||||
final response = await http.get(Uri.parse('http://localhost:6823/read-config'));
|
final response =
|
||||||
|
await http.get(Uri.parse('http://localhost:6823/read-config'));
|
||||||
print(response.statusCode);
|
print(response.statusCode);
|
||||||
print(response.body);
|
print(response.body);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
@ -175,15 +191,16 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Map<String, dynamic> updates = {
|
Map<String, dynamic> updates = {
|
||||||
"username": email,
|
// "username": email,
|
||||||
"password": password,
|
// "password": password,
|
||||||
"api_addr": ip,
|
"ip": ip,
|
||||||
"api_port": port,
|
"port": port,
|
||||||
};
|
};
|
||||||
print("past");
|
print("past");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final sending = await http.post(Uri.parse('http://localhost:6823/update-config'),
|
final sending = await http.post(
|
||||||
|
Uri.parse('http://localhost:6823/update-config'),
|
||||||
headers: {'Content-Type': "application/json"},
|
headers: {'Content-Type': "application/json"},
|
||||||
body: jsonEncode(updates));
|
body: jsonEncode(updates));
|
||||||
print("sending");
|
print("sending");
|
||||||
@ -193,10 +210,12 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// String status = await http.post(Uri.parse(''))
|
// String status = await http.post(Uri.parse(''))
|
||||||
var url_log = Uri.http('localhost:6823', 'log_in');
|
var url_log = Uri.http('$ip:$port', 'log_in');
|
||||||
Map<String, dynamic> filteredData = {
|
Map<String, dynamic> filteredData = {
|
||||||
'email': updates['username'],
|
"email": email,
|
||||||
'password': updates['password']
|
"password": password,
|
||||||
|
// 'email': updates['username'],
|
||||||
|
// 'password': updates['password']
|
||||||
};
|
};
|
||||||
print(filteredData);
|
print(filteredData);
|
||||||
var status = await http.post(
|
var status = await http.post(
|
||||||
@ -209,6 +228,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
if (status.statusCode == 200) {
|
if (status.statusCode == 200) {
|
||||||
print('response status ${status.body}');
|
print('response status ${status.body}');
|
||||||
if (status.body == "Successful log in") {
|
if (status.body == "Successful log in") {
|
||||||
|
ApiService.ip = ip;
|
||||||
|
ApiService.port = port;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user