nearly done login, only missing the other fields which are on the conf, but those should be made into a more user friendly way, where it should parse the email username, and from it fill out the imap server and what not
This commit is contained in:
parent
d481981395
commit
0b382d72f4
@ -28,6 +28,14 @@ android {
|
|||||||
targetSdk = flutter.targetSdkVersion
|
targetSdk = flutter.targetSdkVersion
|
||||||
versionCode = flutter.versionCode
|
versionCode = flutter.versionCode
|
||||||
versionName = flutter.versionName
|
versionName = flutter.versionName
|
||||||
|
ndk {
|
||||||
|
abiFilters.addAll(listOf("arm64-v8a", "x86_64"))
|
||||||
|
}
|
||||||
|
sourceSets {
|
||||||
|
getByName("main") {
|
||||||
|
jniLibs.srcDirs("src/main/jniLibs")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
211
lib/login.dart
211
lib/login.dart
@ -12,21 +12,21 @@ import 'package:flutter/services.dart' show rootBundle;
|
|||||||
|
|
||||||
class AuthService extends ChangeNotifier {
|
class AuthService extends ChangeNotifier {
|
||||||
Future<bool> isUserLoggedIn() async {
|
Future<bool> isUserLoggedIn() async {
|
||||||
ApiService.ip = '192.168.2.38';
|
// ApiService.ip = '127.0.0.1';
|
||||||
ApiService.port = '3001';
|
// ApiService.port = '3001';
|
||||||
print("setted up");
|
// print("setted up");
|
||||||
|
|
||||||
return true;
|
// return true;
|
||||||
try {
|
try {
|
||||||
final response =
|
final response =
|
||||||
await http.get(Uri.http('localhost:6823', 'read-config'));
|
await http.get(Uri.http('127.0.0.1:6767', 'login_check'));
|
||||||
// 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) {
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(response.body);
|
||||||
// return data['config'];
|
// print(data['state']);
|
||||||
|
// return true;
|
||||||
try {
|
try {
|
||||||
var url = Uri.http('${data['ip']}:${data['port']}', 'is_logged_in');
|
var url = Uri.http('${data['ip']}:${data['port']}', 'is_logged_in');
|
||||||
var response = await http.get(url);
|
var response = await http.get(url);
|
||||||
@ -106,18 +106,25 @@ class _SplashScreenState extends State<SplashScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _checkLoginStatus() async {
|
Future<void> _checkLoginStatus() async {
|
||||||
// SharedPreferences prefs = await SharedPreferences.getInstance();
|
try {
|
||||||
// print(prefs);
|
final response =
|
||||||
// bool isLoggedIn = prefs.getBool('isLoggedIn') ?? false;
|
await http.get(Uri.parse('http://127.0.0.1:6767/login_check'));
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
print(response.statusCode);
|
||||||
bool isLoggedIn = await _authService.isUserLoggedIn();
|
print(response.body);
|
||||||
print("is logged in $isLoggedIn");
|
if (response.statusCode == 200) {
|
||||||
if (isLoggedIn) {
|
final data = jsonDecode(response.body);
|
||||||
context.go("/home");
|
print(data['state']);
|
||||||
// Navigator.pushReplacementNamed(context, '/home');
|
if (data['state']) {
|
||||||
} else {
|
context.go("/home");
|
||||||
|
} else {
|
||||||
|
context.go("/login");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.go("/login");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("caught in checkloginstatus in login $e");
|
||||||
context.go("/login");
|
context.go("/login");
|
||||||
// Navigator.pushReplacementNamed(context, '/login');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,14 +146,10 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
final TextEditingController _emailController = TextEditingController();
|
final TextEditingController _emailController = TextEditingController();
|
||||||
final TextEditingController _passwordController = TextEditingController();
|
final TextEditingController _passwordController = TextEditingController();
|
||||||
|
|
||||||
// final ConfigManager _configManager =
|
|
||||||
// ConfigManager("${Directory.current.parent}../crabmail2.conf");
|
|
||||||
// Key to identify the form
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
Future<bool> setIp(String ip) async {
|
Future<bool> setIp(String ip) async {
|
||||||
//this is not done :sob: :skull:
|
//this is not done :sob: :skull:
|
||||||
// _configManager.setField("api_addr", ip);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,31 +158,16 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> login() async {
|
Future<void> login() async {
|
||||||
bool result = await _handleLogin();
|
var result = await _handleLogin();
|
||||||
if (result) {
|
if (result[0]) {
|
||||||
Navigator.pushReplacementNamed(context, '/home');
|
ApiService.ip = result[1];
|
||||||
|
ApiService.port = result[2];
|
||||||
|
context.go('/home');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Future<bool> _checkConfiguration() async {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void checkLogin() async {
|
|
||||||
// try {
|
|
||||||
// var url = Uri.http('127.0.0.1:3001', 'is_logged_in');
|
|
||||||
// var response = await http.get(url);
|
|
||||||
// print(response.body);
|
|
||||||
// if (response.statusCode == 200) {
|
|
||||||
// print('all good on the west');
|
|
||||||
// }
|
|
||||||
// } catch (e) {
|
|
||||||
// print(e);
|
|
||||||
// }
|
|
||||||
// // bool isLoggedIn = await _authService.isUserLoggedIn();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Function to handle login action
|
// Function to handle login action
|
||||||
Future<bool> _handleLogin() async {
|
Future<List> _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;
|
||||||
@ -193,96 +181,64 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
print(ip);
|
print(ip);
|
||||||
print(port);
|
print(port);
|
||||||
|
|
||||||
String baseUrl = "http://$ip:$port";
|
|
||||||
print("baseurl " + baseUrl);
|
|
||||||
print(baseUrl);
|
|
||||||
try {
|
try {
|
||||||
final response =
|
Map<String, String> requestBody = {
|
||||||
await http.get(Uri.parse('http://localhost:6823/read-config'));
|
"user": email,
|
||||||
|
"password": password,
|
||||||
|
"ip": ip,
|
||||||
|
"port": port,
|
||||||
|
};
|
||||||
|
var url = Uri.http("$ip:6767", "login");
|
||||||
|
|
||||||
|
final response = await http.post(url,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: jsonEncode(
|
||||||
|
requestBody)); //keep the port but change the ip to the server that will process it?
|
||||||
print(response.statusCode);
|
print(response.statusCode);
|
||||||
print(response.body);
|
print(response.body);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(response.body);
|
||||||
// return data['config'];
|
if (data["state"] == true) {
|
||||||
|
try {
|
||||||
|
final response = await http
|
||||||
|
.get(Uri.parse('http://127.0.0.1:6767/login_check'));
|
||||||
|
print(response.statusCode);
|
||||||
|
print(response.body);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final data = jsonDecode(response.body);
|
||||||
|
print(data['state']);
|
||||||
|
if (data['state']) {
|
||||||
|
context.go("/home");
|
||||||
|
} else {
|
||||||
|
context.go("/login");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.go("/login");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("caught in checkloginstatus in login $e");
|
||||||
|
context.go("/login");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [true, ip, port];
|
||||||
}
|
}
|
||||||
|
return [false];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("caught in catch");
|
print("caught in catch");
|
||||||
print(e);
|
print(e);
|
||||||
return false;
|
return [false];
|
||||||
}
|
}
|
||||||
Map<String, dynamic> updates = {
|
|
||||||
// "username": email,
|
|
||||||
// "password": password,
|
|
||||||
"ip": ip,
|
|
||||||
"port": port,
|
|
||||||
};
|
|
||||||
print("past");
|
|
||||||
|
|
||||||
try {
|
|
||||||
final sending = await http.post(
|
|
||||||
Uri.parse('http://localhost:6823/update-config'),
|
|
||||||
headers: {'Content-Type': "application/json"},
|
|
||||||
body: jsonEncode(updates));
|
|
||||||
print("sending");
|
|
||||||
} catch (e) {
|
|
||||||
print(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// String status = await http.post(Uri.parse(''))
|
|
||||||
var url_log = Uri.http('$ip:$port', 'log_in');
|
|
||||||
Map<String, dynamic> filteredData = {
|
|
||||||
"email": email,
|
|
||||||
"password": password,
|
|
||||||
// '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") {
|
|
||||||
ApiService.ip = ip;
|
|
||||||
ApiService.port = port;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
print("after");
|
|
||||||
return false;
|
|
||||||
// final content = await _authService.readConfFile();
|
|
||||||
// final config = await _authService.parseConfFile(content);
|
|
||||||
// print("BASE URL ${config["base_url"]}");
|
|
||||||
// print("api address ${config["api_addr"]}");
|
|
||||||
// print(config);
|
|
||||||
// const url = ''
|
|
||||||
// Clear the input fields
|
|
||||||
// _ipController.clear();
|
|
||||||
// _portController.clear();
|
|
||||||
// _emailController.clear();
|
|
||||||
// _passwordController.clear();
|
|
||||||
}
|
}
|
||||||
return false;
|
return [false];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// try {
|
_ipController.text = "127.0.0.1";
|
||||||
// _configManager.loadConfig();
|
_portController.text = "3001";
|
||||||
// print(_configManager.getField('base_url'));
|
|
||||||
// } catch (e) {
|
|
||||||
// print("broke at build $e");
|
|
||||||
// }
|
|
||||||
// _configManager.
|
|
||||||
return Center(
|
return Center(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -317,14 +273,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
return 'Please enter your ip';
|
return 'Please enter your ip';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// onSaved: (value) async {
|
|
||||||
// final content = await _authService.readConfFile();
|
|
||||||
// final config =
|
|
||||||
// await _authService.parseConfFile(content);
|
|
||||||
// print("BASE URL ${config["base_url"]}");
|
|
||||||
// print("api address ${config["api_addr"]}");
|
|
||||||
// //TODO: call a function to set the field ip in conf
|
|
||||||
// },
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
@ -403,17 +351,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
child: const Text('Login'),
|
child: const Text('Login'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// SizedBox(
|
|
||||||
// width: 200,
|
|
||||||
// child: ElevatedButton(
|
|
||||||
// // onPressed: checkLogin,
|
|
||||||
// onPressed: () async {
|
|
||||||
// await _authService.isUserLoggedIn();
|
|
||||||
// // print(result);
|
|
||||||
// },
|
|
||||||
// child: const Text('checker'),
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -33,6 +33,7 @@ dependencies:
|
|||||||
go_router: ^16.0.0
|
go_router: ^16.0.0
|
||||||
super_editor: ^0.3.0-dev.27
|
super_editor: ^0.3.0-dev.27
|
||||||
super_editor_markdown: 0.1.8
|
super_editor_markdown: 0.1.8
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user