mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 05:52:51 +00:00
Added create connection
This commit is contained in:
parent
a97ae20631
commit
3acfc7c5a5
10 changed files with 411 additions and 21 deletions
|
@ -8,7 +8,7 @@ Future<Map<String, dynamic>> loadDb() async {
|
|||
'adguard_home_manager.db',
|
||||
version: 1,
|
||||
onCreate: (Database db, int version) async {
|
||||
await db.execute("CREATE TABLE servers (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, connectionMethod TEXT, domain TEXT, path TEXT, port INTEGER, user TEXT, password TEXT, defaultServer INTEGER)");
|
||||
await db.execute("CREATE TABLE servers (id TEXT PRIMARY KEY, name TEXT, connectionMethod TEXT, domain TEXT, path TEXT, port INTEGER, user TEXT, password TEXT, defaultServer INTEGER)");
|
||||
},
|
||||
onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
||||
|
||||
|
|
47
lib/services/http_requests.dart
Normal file
47
lib/services/http_requests.dart
Normal file
|
@ -0,0 +1,47 @@
|
|||
// ignore_for_file: depend_on_referenced_packages
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:adguard_home_manager/models/server.dart';
|
||||
|
||||
Future login(Server server) async {
|
||||
try {
|
||||
final result = await http.post(
|
||||
Uri.parse("${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}/control/login"),
|
||||
body: jsonEncode({
|
||||
"name": server.user,
|
||||
"password": server.password
|
||||
})
|
||||
);
|
||||
if (result.statusCode == 200) {
|
||||
return {'result': 'success'};
|
||||
}
|
||||
else if (result.statusCode == 400) {
|
||||
return {
|
||||
'result': 'error',
|
||||
'message': 'invalid_username_password'
|
||||
};
|
||||
}
|
||||
else if (result.statusCode == 429) {
|
||||
return {
|
||||
'result': 'error',
|
||||
'message': 'many_attempts'
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {'result': 'error'};
|
||||
}
|
||||
} on SocketException {
|
||||
return {'result': 'no_connection'};
|
||||
} on TimeoutException {
|
||||
return {'result': 'no_connection'};
|
||||
} on HandshakeException {
|
||||
return {'result': 'ssl_error'};
|
||||
} catch (e) {
|
||||
return {'result': 'error'};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue