diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 2ef35ac..8ef85e5 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -8,8 +8,7 @@
3.3.3)
+ - UXCam (~> 3.3.4)
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
@@ -367,7 +367,7 @@ SPEC CHECKSUMS:
flutter_facebook_auth: 4b170c07b7fce791497093fcc3f134fb215f3f07
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
- flutter_uxcam: 87dd981feb200bc81a2f062edb5ca2d16dae595a
+ flutter_uxcam: ab8e5d3954eb448febd581375e2622e9eecb1066
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
google_sign_in: 6bd214b9c154f881422f5fe27b66aaa7bbd580cc
GoogleAppMeasurement: fd19169c3034975cb934e865e5667bfdce59df7f
diff --git a/lib/model/cache.dart b/lib/model/cache.dart
index cfb077e..f5ce731 100644
--- a/lib/model/cache.dart
+++ b/lib/model/cache.dart
@@ -104,7 +104,9 @@ class Cache with Logging {
static final String activeExercisePlanDateKey = "active_exercise_plan_date";
static final String activeExercisePlanDetailsKey = "active_exercise_details_plan";
- static String baseUrl = 'http://aitrainer.info:8888/api/';
+ static String baseUrlLive = 'https://aitrainer.info:8943/api/';
+ static String baseUrlTest = 'https://aitrainer.info:8843/api/';
+ late String baseUrl;
static final String mediaUrl = 'https://aitrainer.info:4343/media/';
static final String username = 'bosi';
static final String password = 'andio2009';
@@ -171,7 +173,7 @@ class Cache with Logging {
String testEnv = EnvironmentConfig.test_env;
this.testEnvironment = testEnv;
if (testEnv == "1") {
- baseUrl = 'http://aitrainer.app:8899/api/';
+ baseUrl = baseUrlTest;
liveServer = false;
}
@@ -181,7 +183,7 @@ class Cache with Logging {
}
void setTestBaseUrl() {
- baseUrl = 'http://aitrainer.app:8899/api/';
+ baseUrl = baseUrlTest;
}
String getAuthToken() {
@@ -288,22 +290,22 @@ class Cache with Logging {
void setServerAddress(SharedPreferences prefs) {
if (this.testEnvironment == "1") {
- baseUrl = 'http://aitrainer.app:8899/api/';
+ baseUrl = baseUrlTest;
print("TestEnv $baseUrl");
return;
}
final bool? live = prefs.getBool(Cache.serverKey);
if (live == null) {
- baseUrl = 'http://aitrainer.app:8888/api/';
+ baseUrl = baseUrlLive;
print("Live Env $baseUrl");
liveServer = true;
return;
}
liveServer = live;
if (live) {
- baseUrl = 'http://aitrainer.info:8888/api/';
+ baseUrl = baseUrlLive;
} else {
- baseUrl = 'http://aitrainer.app:8899/api/';
+ baseUrl = baseUrlTest;
}
print("Env $baseUrl");
@@ -331,7 +333,7 @@ class Cache with Logging {
return prefs.getString(authTokenKey);
}
- static String getBaseUrl() {
+ String getBaseUrl() {
return baseUrl;
}
diff --git a/lib/service/api.dart b/lib/service/api.dart
index b1f5b88..6a98b3d 100644
--- a/lib/service/api.dart
+++ b/lib/service/api.dart
@@ -1,13 +1,120 @@
import 'dart:convert';
+import 'dart:io';
+import 'package:aitrainer_app/model/result.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/not_found_exception.dart';
+import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:aitrainer_app/model/cache.dart';
class APIClient with Common, Logging {
+ Future sendRequestToServer(dynamic model, String reqType, bool isTokenHeader, String token) async {
+ HttpClient client = new HttpClient();
+ client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
+ HttpClientRequest request = await client.postUrl(Uri.parse(Cache().getBaseUrl() + reqType));
+ request.headers.set('Content-Type', 'application/json');
+ if (isTokenHeader) {
+ request.headers.set('Authorization', 'Bearer $token');
+ }
+ request.add(utf8.encode(jsonEncode(model)));
+ HttpClientResponse result = await request.close();
+ if (result.statusCode == 200) {
+ return jsonDecode(await result.transform(utf8.decoder).join());
+ } else {
+ return null;
+ }
+ }
+
+ dynamic authenticateUser(String email, String password) async {
+ var url = Cache().getBaseUrl() + "authenticate";
+
+ try {
+ ByteData data = await rootBundle.load('asset/data/aitrainer_server.crt.pem');
+ SecurityContext context = SecurityContext.defaultContext;
+ context.setTrustedCertificatesBytes(data.buffer.asUint8List(), password: "[xxxx]");
+
+ HttpClient client = new HttpClient(); //context: context Todo provide the right certificate
+ client.badCertificateCallback = ((X509Certificate cert, String host, int port) {
+ print("Host: $host Port: $port");
+ return true;
+ });
+ var uri = Uri.parse(url);
+ final HttpClientRequest request = await client.postUrl(uri);
+ request.headers.set('Content-Type', 'application/json');
+ request.headers.set('Authorization', '1');
+
+ final body = '{"username":"$email", "password":"$password"}';
+ request.write(body);
+ HttpClientResponse result = await request.close();
+ if (result.statusCode != 200) {
+ trace("authentication response: ${result.statusCode}");
+ throw Exception("Network error, try again later!");
+ }
+ return jsonDecode(await result.transform(utf8.decoder).join());
+ } catch (exception) {
+ print(exception.toString());
+ throw Exception("Network error, try again later!");
+ }
+ }
+
+ Future post(String endPoint, String body) async {
+ final url = Cache().getBaseUrl() + endPoint;
+ trace(" ------------ http/post body $body - url: $url ");
+ String authToken = Cache().getAuthToken();
+ if (authToken.length == 0) {
+ var responseJson = await this.authenticateUser(Cache.username, Cache.password);
+ authToken = responseJson['token'];
+ Cache().authToken = authToken;
+ }
+ var uri = Uri.parse(url);
+ HttpClient client = new HttpClient();
+ client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
+ final HttpClientRequest request = await client.getUrl(uri);
+ request.headers.set('Content-Type', 'application/json');
+ request.headers.set('Authorization', 'Bearer $authToken');
+ request.write(body);
+ HttpClientResponse result = await request.close();
+ trace(" ------------post response code: " + result.statusCode.toString());
+ if (result.statusCode == 200) {
+ return await result.transform(utf8.decoder).join();
+ } else if (result.statusCode == 404) {
+ throw NotFoundException(message: "Not Found");
+ } else {
+ throw Exception("Network Error, please try again later");
+ }
+ }
+
Future get(String endPoint, String param) async {
- final url = Cache.getBaseUrl() + endPoint + param;
+ final url = Cache().getBaseUrl() + endPoint + param;
+
+ trace("-------- API get " + url);
+ String authToken = Cache().getAuthToken();
+ if (authToken.length == 0) {
+ var responseJson = await this.authenticateUser(Cache.username, Cache.password);
+ authToken = responseJson['token'];
+ Cache().authToken = authToken;
+ }
+ var uri = Uri.parse(url);
+
+ HttpClient client = new HttpClient();
+ client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
+ final HttpClientRequest request = await client.getUrl(uri);
+ request.headers.set('Content-Type', 'application/json');
+ request.headers.set('Authorization', 'Bearer $authToken');
+ HttpClientResponse result = await request.close();
+ trace(" ------------get response code: " + result.statusCode.toString());
+ if (result.statusCode == 200) {
+ return await result.transform(utf8.decoder).join();
+ } else if (result.statusCode == 404) {
+ throw NotFoundException(message: "Not Found");
+ } else {
+ throw Exception("Network Error, please try again later");
+ }
+ }
+
+ Future get0(String endPoint, String param) async {
+ final url = Cache().getBaseUrl() + endPoint + param;
trace("-------- API get " + url);
String authToken = Cache().getAuthToken();
@@ -28,8 +135,8 @@ class APIClient with Common, Logging {
}
}
- Future post(String endPoint, String body) async {
- final url = Cache.getBaseUrl() + endPoint;
+ Future post0(String endPoint, String body) async {
+ final url = Cache().getBaseUrl() + endPoint;
trace(" ------------ http/post body $body - url: $url ");
String authToken = Cache().getAuthToken();
if (authToken.length == 0) {
@@ -48,8 +155,8 @@ class APIClient with Common, Logging {
return decodedResponse;
}
- dynamic authenticateUser(String email, String password) async {
- var url = Cache.getBaseUrl() + "authenticate";
+ dynamic authenticateUser0(String email, String password) async {
+ var url = Cache().getBaseUrl() + "authenticate";
try {
final body = '{"username":"$email", "password":"$password"}';
@@ -74,7 +181,7 @@ class APIClient with Common, Logging {
}
Future fetch(var authToken, var endPoint) async {
- var url = Cache.getBaseUrl() + endPoint;
+ var url = Cache().getBaseUrl() + endPoint;
try {
var uri = Uri.parse(url);
diff --git a/pubspec.lock b/pubspec.lock
index 4751a46..c1ee976 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -547,7 +547,7 @@ packages:
name: flutter_uxcam
url: "https://pub.dartlang.org"
source: hosted
- version: "1.3.2"
+ version: "2.0.0-beta.1"
flutter_web_plugins:
dependency: transitive
description: flutter
@@ -608,7 +608,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
- version: "0.13.1"
+ version: "0.13.3"
http_multi_server:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index eb9ebda..2ed78bd 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
-version: 1.1.14+74
+version: 1.1.14+75
environment:
sdk: ">=2.12.0 <3.0.0"
@@ -71,7 +71,7 @@ dependencies:
#smartlook: ^1.0.7
flurry: ^0.0.4
- flutter_uxcam: ^1.3.2
+ flutter_uxcam: ^2.0.0-beta.1
animated_widgets: ^1.0.6
@@ -95,7 +95,7 @@ dev_dependencies:
build_runner:
- http: ^0.13.1
+ http: ^0.13.3
intl: ^0.17.0
shared_preferences: ^2.0.5
@@ -122,6 +122,8 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
+ - asset/data/aitrainer_server.crt.pem
+
- asset/icon/gomb_kek_a-2.png
- asset/icon/gomb_kek_b.png
- asset/icon/gomb_lila_b.png