WT1.1.2 build 32 login error messages fixes

This commit is contained in:
bossanyit 2020-11-20 15:32:06 +01:00
parent 3ce32434bf
commit ed8760f8e8
13 changed files with 90 additions and 97 deletions

View File

@ -177,7 +177,7 @@
};
};
};
buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject " " */;
buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */;
compatibilityVersion = "Xcode 10.0";
developmentRegion = en;
hasScannedForEncodings = 0;
@ -362,7 +362,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = SFJJBDCU6Z;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
@ -505,7 +505,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = SFJJBDCU6Z;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
@ -540,7 +540,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 31;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = SFJJBDCU6Z;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
@ -570,7 +570,7 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
97C146E91CF9000F007C117D /* Build configuration list for PBXProject " " */ = {
97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = {
isa = XCConfigurationList;
buildConfigurations = (
97C147031CF9000F007C117D /* Debug */,

View File

@ -33,6 +33,8 @@
<string>584181112271127</string>
<key>FacebookDisplayName</key>
<string>Mobile Login</string>
<key>FirebaseAppDelegateProxyEnabled</key>
<string>NO</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
@ -66,7 +68,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>FirebaseAppDelegateProxyEnabled</key>
<string>NO</string>
</dict>
</plist>

View File

@ -16,6 +16,9 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
double height = 170;
CustomerChangeBloc({this.customerRepository}) : super(CustomerChangeInitial()) {
year = this.customerRepository.customer.birthYear;
if (year == 0) {
year = 1990;
}
weight = this.customerRepository.getWeight();
height = this.customerRepository.getHeight();
}

View File

@ -288,6 +288,10 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> {
}
double getBMI() {
if (height == 0) {
this.bmi = 0;
return 0;
}
this.bmi = weight / (height * height / 10000);
this.getGoalBMI();
return this.bmi;

View File

@ -47,8 +47,11 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
} else {
// Emit either Loaded or Error
await PropertyApi().getProperties();
print("properties OK");
await userRepository.getUser();
print("get User OK");
await ExerciseTypeApi().getExerciseTypes();
print("exerciesTypes OK");
await ExerciseTreeApi().getExerciseTree();
if (Cache().userLoggedIn != null && Cache().userLoggedIn.customerId > 0) {
ExerciseRepository exerciseRepository = ExerciseRepository();

View File

@ -17,8 +17,7 @@ class AppLocalizations {
}
// Static member to have a simple access to the delegate from the MaterialApp
static const LocalizationsDelegate<AppLocalizations> delegate =
AppLocalizationsDelegate();
static const LocalizationsDelegate<AppLocalizations> delegate = AppLocalizationsDelegate();
Map<String, String> _localizedStrings;
@ -29,8 +28,7 @@ class AppLocalizations {
Future<bool> load() async {
// Load the language JSON file from the "lang" folder
print(" -- load language pieces " + locale.languageCode);
String jsonString =
await rootBundle.loadString('i18n/${locale.languageCode}.json');
String jsonString = await rootBundle.loadString('i18n/${locale.languageCode}.json');
Map<String, dynamic> jsonMap = json.decode(jsonString);
_localizedStrings = jsonMap.map((key, value) {
@ -47,13 +45,12 @@ class AppLocalizations {
// This method will be called from every widget which needs a localized text
String translate(String key) {
if (isTest) return key;
return _localizedStrings[key];
String translated = _localizedStrings[key];
return translated != null ? translated : key;
}
}
class AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
final bool isTest;
// This delegate instance will never change (it doesn't even have fields!)
// It can provide a constant constructor.
@ -77,7 +74,6 @@ class AppLocalizationsDelegate
return localizations;
}
@override
bool shouldReload(AppLocalizationsDelegate old) => false;
}

View File

@ -7,7 +7,7 @@ class UserRepository {
User user;
UserRepository() {
this.createNewUser();
this.createNewUser();
}
setEmail(String email) {
@ -24,10 +24,15 @@ class UserRepository {
Future<void> addUser() async {
final User modelUser = this.user;
String rc = await FirebaseApi().registerEmail(modelUser.email, modelUser.password);
if ( rc == FirebaseApi.SIGN_IN_OK ) {
modelUser.firebaseUid = Cache().firebaseUid;
await CustomerApi().addUser(modelUser);
try {
String rc = await FirebaseApi().registerEmail(modelUser.email, modelUser.password);
if (rc == FirebaseApi.SIGN_IN_OK) {
modelUser.firebaseUid = Cache().firebaseUid;
await CustomerApi().addUser(modelUser);
}
} catch (e) {
print(e.toString());
throw new Exception(e);
}
}
@ -35,12 +40,14 @@ class UserRepository {
final User modelUser = this.user;
String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password);
if ( rc == FirebaseApi.SIGN_IN_OK ) {
if (rc == FirebaseApi.SIGN_IN_OK) {
print("Firebase login ok");
await CustomerApi().getUserByEmail(modelUser.email);
print("GetUserBy Email OK");
Cache().afterFirebaseLogin();
} else {
throw Exception("Exception: Customer does not exist or the password is wrong");
print("Exception: user not found or password is wrong");
throw Exception("Customer does not exist or the password is wrong");
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -51,7 +51,8 @@ class _LoginWidget extends State<LoginWidget> with Common, Trans {
},
onFailure: (context, state) {
LoadingDialog.hide(context);
showInSnackBar(t(state.failureResponse));
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.orange, content: Text(t(state.failureResponse), style: TextStyle(color: Colors.white))));
},
onLoaded: (context, state) {},
child: loadForm(loginBloc, accountBloc)),
@ -159,9 +160,4 @@ class _LoginWidget extends State<LoginWidget> with Common, Trans {
])),
);
}
void showInSnackBar(String error) {
_scaffoldKey.currentState
.showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(error, style: TextStyle(color: Colors.white))));
}
}

View File

@ -4,6 +4,7 @@ import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/user_repository.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar_min.dart';
import 'package:aitrainer_app/widgets/splash.dart';
import 'package:flutter/material.dart';
@ -34,11 +35,12 @@ class RegistrationWidget extends StatefulWidget {
State<StatefulWidget> createState() => _RegistrationWidget();
}
class _RegistrationWidget extends State<RegistrationWidget> with Common {
class _RegistrationWidget extends State<RegistrationWidget> with Common, Trans {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
setContext(context);
// ignore: close_sinks
final accountBloc = BlocProvider.of<AccountBloc>(context);
return BlocProvider(
@ -60,7 +62,8 @@ class _RegistrationWidget extends State<RegistrationWidget> with Common {
},
onFailure: (context, state) {
LoadingDialog.hide(context);
showInSnackBar(state.failureResponse);
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.orange, content: Text(t(state.failureResponse), style: TextStyle(color: Colors.white))));
},
child: SafeArea(
bottom: false,
@ -158,11 +161,4 @@ class _RegistrationWidget extends State<RegistrationWidget> with Common {
);
}));
}
void showInSnackBar(String error) {
_scaffoldKey.currentState.showSnackBar(SnackBar(
backgroundColor: Colors.orange,
content: Text(AppLocalizations.of(context).translate("There is an error: during registration:") + " " + error,
style: TextStyle(color: Colors.white))));
}
}

View File

@ -168,7 +168,6 @@ class _BMRState extends State<BMR> with Trans {
Widget getFitnessLevel() {
String fitnessLevel = widget.exerciseBloc.fitnessLevel;
print("sel " + fitnessLevel + FitnessItem().getItem(fitnessLevel).stateText);
return Container(
padding: EdgeInsets.only(left: 65, right: 65),
child: DropdownSearch<FitnessState>(