WT1.1.2 build 32 login error messages fixes
This commit is contained in:
+20
-44
@@ -5,26 +5,18 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
|
||||
class APIClient with Common {
|
||||
|
||||
Future<String> get(String endPoint, String param) async {
|
||||
final url = Cache.getBaseUrl() + endPoint + param;
|
||||
String authToken = Cache().getAuthToken();
|
||||
if ( authToken.length == 0 ) {
|
||||
var responseJson = await APIClient.authenticateUser(
|
||||
Cache.username,
|
||||
Cache.password
|
||||
);
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await APIClient.authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
}
|
||||
final response = await http.get(url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization' : "Bearer " + authToken }
|
||||
);
|
||||
final response = await http.get(url, headers: {'Content-Type': 'application/json', 'Authorization': "Bearer " + authToken});
|
||||
print(" ------------get response code: " + response.statusCode.toString());
|
||||
if(response.statusCode == 200) {
|
||||
if (response.statusCode == 200) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
} else if(response.statusCode == 404 ) {
|
||||
} else if (response.statusCode == 404) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
} else {
|
||||
throw Exception("Network Error, please try again later");
|
||||
@@ -35,20 +27,15 @@ class APIClient with Common {
|
||||
final url = Cache.getBaseUrl() + endPoint;
|
||||
print(" ------------ http/post endpoint $endPoint body $body - url: $url ");
|
||||
String authToken = Cache().getAuthToken();
|
||||
if ( authToken.length == 0 ) {
|
||||
var responseJson = await APIClient.authenticateUser(
|
||||
Cache.username,
|
||||
Cache.password
|
||||
);
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await APIClient.authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
}
|
||||
|
||||
final response = await http.post(url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization' : "Bearer " + authToken
|
||||
},
|
||||
body: body,
|
||||
final response = await http.post(
|
||||
url,
|
||||
headers: {'Content-Type': 'application/json; charset=UTF-8', 'Authorization': "Bearer " + authToken},
|
||||
body: body,
|
||||
);
|
||||
print(" ------------post response code: " + response.statusCode.toString());
|
||||
final String decodedResponse = utf8convert(response.body);
|
||||
@@ -62,25 +49,18 @@ class APIClient with Common {
|
||||
try {
|
||||
final body = '{"username":"$email", "password":"$password"}';
|
||||
print("authentication with $email");
|
||||
final response = await http.post(
|
||||
uri,
|
||||
headers: {
|
||||
'Authorization': '1',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: body
|
||||
);
|
||||
final response = await http.post(uri, headers: {'Authorization': '1', 'Content-Type': 'application/json'}, body: body);
|
||||
final responseCode = response.statusCode;
|
||||
if ( responseCode != 200) {
|
||||
return { "error" : "Authentication error, total failure", };
|
||||
if (responseCode != 200) {
|
||||
return {
|
||||
"error": "Authentication error, total failure",
|
||||
};
|
||||
}
|
||||
|
||||
final responseJson = json.decode(response.body);
|
||||
return responseJson;
|
||||
|
||||
} catch (exception) {
|
||||
return { "error" : "Network error, try again later "
|
||||
+ exception.toString()};
|
||||
return {"error": "Network error, try again later " + exception.toString()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,22 +70,18 @@ class APIClient with Common {
|
||||
try {
|
||||
final response = await http.get(
|
||||
uri,
|
||||
headers: {
|
||||
'Authorization': authToken
|
||||
},
|
||||
headers: {'Authorization': authToken},
|
||||
);
|
||||
|
||||
final responseJson = json.decode(response.body);
|
||||
return responseJson;
|
||||
|
||||
} catch (exception) {
|
||||
print(exception);
|
||||
if(exception.toString().contains('SocketException')) {
|
||||
if (exception.toString().contains('SocketException')) {
|
||||
return 'NetworkError';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/model/user.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
|
||||
class CustomerApi {
|
||||
final APIClient _client = new APIClient();
|
||||
@@ -72,12 +73,14 @@ class CustomerApi {
|
||||
Customer customer;
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
/* if (customer.firebaseUid == null) {
|
||||
if (customer.firebaseUid == null) {
|
||||
await this.updateFirebaseUid(customer.customerId, Cache().firebaseUid);
|
||||
} */
|
||||
}
|
||||
Cache().userLoggedIn = customer;
|
||||
final List properties = await this.getActualProperties(customer.customerId);
|
||||
this._initProperties(properties);
|
||||
if (properties != null) {
|
||||
this._initProperties(properties);
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
}
|
||||
@@ -93,8 +96,10 @@ class CustomerApi {
|
||||
final List properties = await this.getActualProperties(customerId);
|
||||
print(" ---- Props: " + properties.toString());
|
||||
Cache().afterRegistration(customer);
|
||||
this._initProperties(properties);
|
||||
} catch (exception) {
|
||||
if (properties != null) {
|
||||
this._initProperties(properties);
|
||||
}
|
||||
} on Exception catch (exception) {
|
||||
print("Exception: " + exception.toString());
|
||||
print(" === go to registration ");
|
||||
Cache().logout();
|
||||
@@ -162,13 +167,20 @@ class CustomerApi {
|
||||
}
|
||||
|
||||
Future<List<CustomerProperty>> getActualProperties(int customerId) async {
|
||||
final body = await _client.get("customer_property/last/", customerId.toString());
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<CustomerProperty> properties = json.map((property) => CustomerProperty.fromJson(property)).toList();
|
||||
List<CustomerProperty> properties;
|
||||
try {
|
||||
final body = await _client.get("customer_property/last/", customerId.toString());
|
||||
final Iterable json = jsonDecode(body);
|
||||
properties = json.map((property) => CustomerProperty.fromJson(property)).toList();
|
||||
|
||||
properties.forEach((element) {
|
||||
print("Property " + element.toString());
|
||||
});
|
||||
if (properties != null) {
|
||||
properties.forEach((element) {
|
||||
print("Property " + element.toString());
|
||||
});
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
print(ex.toString());
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,11 @@ class FirebaseApi {
|
||||
} else if (e.code == 'email-already-in-use') {
|
||||
print('The account already exists for that email.');
|
||||
rc = REGISTER_EMAIL_IN_USE;
|
||||
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
|
||||
throw Exception("The email address has been registered already");
|
||||
/* userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
|
||||
if (rc != null) {
|
||||
rc = SIGN_IN_OK;
|
||||
}
|
||||
} */
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
|
||||
Reference in New Issue
Block a user