wt1.1c auth->cache, control page, animation base exercise percent

This commit is contained in:
Bossanyi Tibor
2020-09-01 16:47:45 +02:00
parent 18d6994068
commit 6b0892ec09
38 changed files with 1148 additions and 261 deletions
+12 -12
View File
@@ -1,20 +1,20 @@
import 'dart:convert';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
import 'package:aitrainer_app/repository/user_repository.dart';
import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';
class Common {
mixin Common {
static const EMAIL_ERROR = "Please type a right email address here.";
static const PASSWORD_ERROR = "The password must have at least 8 characters.";
final EMAIL_ERROR = "Please type a right email address here.";
final PASSWORD_ERROR = "The password must have at least 8 characters.";
static String toJson( Map<String, String> map ) {
String toJson( Map<String, String> map ) {
String rc = "{";
map.forEach((key, value) {
rc += "'$key':'$value'";
@@ -23,9 +23,9 @@ class Common {
return rc;
}
static ExerciseType getExerciseType( int exerciseTypeId ) {
ExerciseType getExerciseType( int exerciseTypeId ) {
ExerciseType returnElement = null;
List<ExerciseType> listExerciseType = Auth().getExerciseTypes();
List<ExerciseType> listExerciseType = Cache().getExerciseTypes();
if ( listExerciseType != null ) {
for ( var element in listExerciseType ) {
if (exerciseTypeId == element.exerciseTypeId) {
@@ -37,7 +37,7 @@ class Common {
return returnElement;
}
static String getDateLocale( DateTime datetime, bool timeDisplay ) {
String getDateLocale( DateTime datetime, bool timeDisplay ) {
AppLanguage appLanguage = AppLanguage();
var date = datetime;
@@ -49,16 +49,16 @@ class Common {
return dateName;
}
static String utf8convert(String text) {
String utf8convert(String text) {
List<int> bytes = text.toString().codeUnits;
return utf8.decode(bytes);
}
static double mediaSizeWidth( BuildContext context ) {
double mediaSizeWidth( BuildContext context ) {
return MediaQuery.of(context).size.width;
}
static bool validateEmail(UserRepository userRepository) {
bool validateEmail(UserRepository userRepository) {
final String email = userRepository.user.email;
final RegExp _emailRegExp = RegExp(
r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$',
@@ -66,7 +66,7 @@ class Common {
return _emailRegExp.hasMatch(email);
}
static bool validatePassword(UserRepository userRepository) {
bool validatePassword(UserRepository userRepository) {
final password = userRepository.user.password;
final RegExp _passwordRegExp =
RegExp(r'^(?=.*[A-Za-z0-9])(?=.*\d)[A-Za-z\d]{7,}$');
+23 -17
View File
@@ -1,5 +1,6 @@
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/service/api.dart';
import 'package:aitrainer_app/service/customer_service.dart';
import 'package:aitrainer_app/service/exercise_tree_service.dart';
@@ -7,7 +8,7 @@ import 'package:aitrainer_app/service/exercisetype_service.dart';
import 'package:devicelocale/devicelocale.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:aitrainer_app/model/auth.dart';
import 'package:aitrainer_app/model/cache.dart';
//import '../push_notifications.dart';
@@ -23,7 +24,7 @@ class Session {
_sharedPreferences = await _prefs;
if ( Auth().firstLoad ) {
if ( Cache().firstLoad ) {
print (" -- Session: fetch locale..");
await appLanguage.fetchLocale();
@@ -44,7 +45,7 @@ class Session {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
languages = await Devicelocale.preferredLanguages;
Auth().deviceLanguages = languages;
Cache().deviceLanguages = languages;
print("device langs " + languages.toString());
} on PlatformException {
@@ -64,44 +65,49 @@ class Session {
_fetchToken(SharedPreferences prefs) async {
var responseJson = await APIClient.authenticateUser(
Auth.username,
Auth.password
Cache.username,
Cache.password
);
int customerId = 0;
print("--- Lang: " + appLanguage.appLocal.toString());
if(responseJson['error'] != null) {
print("************** Here big error - no authentication");
} else if (responseJson['token'] != null) {
prefs.setString(Auth.authTokenKey, responseJson['token']);
Auth auth = Auth();
auth.authToken = responseJson['token'];
if (prefs.get(Auth.customerIdKey) == null) {
prefs.setString(Cache.authTokenKey, responseJson['token']);
Cache().authToken = responseJson['token'];
if (prefs.get(Cache.customerIdKey) == null) {
print("************** Registration");
// registration
//Navigator.of(context).pushNamed('registration');
prefs.setBool(Auth.isRegisteredKey, true);
Auth().startPage = "registration";
prefs.setBool(Cache.isRegisteredKey, true);
Cache().startPage = "registration";
} else {
DateTime now = DateTime.now();
DateTime lastStoreDate = DateTime.parse(
prefs.get(Auth.lastStoreDateKey));
prefs.get(Cache.lastStoreDateKey));
DateTime minStoreDate = now.add(Duration(days: -10));
if (lastStoreDate == null ||
lastStoreDate.difference(minStoreDate) > Duration(days: 10) ||
prefs.get(Auth.isLoggedInKey) == null ||
prefs.get(Auth.isLoggedInKey) == false) {
prefs.get(Cache.isLoggedInKey) == null ||
prefs.get(Cache.isLoggedInKey) == false) {
print("************* Login");
//Navigator.of(context).pushNamed('login');
Auth().startPage = "login";
Cache().startPage = "login";
} else {
print("************** Store SharedPreferences");
// get API customer
await CustomerApi().getCustomer(prefs.getInt(Auth.customerIdKey));
Auth().startPage = "home";
customerId = prefs.getInt(Cache.customerIdKey);
await CustomerApi().getCustomer(customerId);
Cache().startPage = "home";
}
await ExerciseTypeApi().getExerciseTypes();
await ExerciseTreeApi().getExerciseTree();
if ( customerId > 0) {
ExerciseRepository exerciseRepository = ExerciseRepository();
exerciseRepository.getExercisesByCustomer(customerId);
}
print("--- Session finished");
}