feat: check if valid guid before synchronization
parent
7c946c7d27
commit
cd3851b2b4
|
|
@ -10,6 +10,7 @@ import 'package:intl/intl.dart';
|
|||
import 'package:mobdr/config/constant.dart';
|
||||
import 'package:mobdr/main.dart';
|
||||
import 'package:mobdr/service/shared_prefs.dart';
|
||||
import 'package:mobdr/service/logger_util.dart';
|
||||
|
||||
class ApiProvider {
|
||||
final Dio _dio;
|
||||
|
|
@ -199,6 +200,30 @@ class ApiProvider {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> guidActif() async {
|
||||
final url =
|
||||
'${ApiConstants.baseUrl}${ApiConstants.mp4Endpoint}${ApiConstants.restEndpoint}/login/${SharedPrefs().login}/guidactif';
|
||||
|
||||
final headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
'Cookie': 'pguid=${SharedPrefs().guid};',
|
||||
};
|
||||
|
||||
final response = await http.get(Uri.parse(url), headers: headers);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final jsonResponse = json.decode(response.body);
|
||||
|
||||
if (jsonResponse.containsKey('general') &&
|
||||
jsonResponse['general']['actif'] == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Synchronize all informations about store, competitor, calendar
|
||||
Future<String> SyncCalendar() async {
|
||||
DateTime now = DateTime.now();
|
||||
|
|
@ -490,6 +515,9 @@ class ApiProvider {
|
|||
|
||||
if (data.containsKey('latest_version')) {
|
||||
if (data['latest_version'] != SharedPrefs().appVersion) {
|
||||
LoggerUtil.logNStackInfo(
|
||||
'A new version is available : ${data['latest_version']}');
|
||||
|
||||
// The versions differ
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:mobdr/main.dart';
|
|||
import 'package:mobdr/events.dart';
|
||||
import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
||||
import 'package:mobdr/ui/appstore/updatecheck.dart';
|
||||
import 'package:mobdr/ui/authentication/signin.dart';
|
||||
import 'package:mobdr/service/shared_prefs.dart';
|
||||
import 'package:mobdr/network/api_provider.dart';
|
||||
import 'package:mobdr/db/box_visit_photo.dart';
|
||||
|
|
@ -40,7 +41,6 @@ class _SynchronizationPageState extends State<SynchronizationPage>
|
|||
super.initState();
|
||||
|
||||
_apiProvider = ApiProvider();
|
||||
|
||||
_animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: Duration(seconds: 2),
|
||||
|
|
@ -71,42 +71,48 @@ class _SynchronizationPageState extends State<SynchronizationPage>
|
|||
} else {
|
||||
_isInternetConnexion = true;
|
||||
|
||||
// synchronization start
|
||||
await startSync();
|
||||
// check if the guid is valid
|
||||
if (await _apiProvider.guidActif() == true) {
|
||||
// synchronization start
|
||||
await startSync();
|
||||
|
||||
// Vérifier si une mise à jour est disponible
|
||||
bool isUpdateAvailable = await _apiProvider.checkAppVersion();
|
||||
|
||||
if (isUpdateAvailable) {
|
||||
// Afficher le message de mise à jour
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text("New version available"),
|
||||
content: Text(
|
||||
"A new version is available. Would you like to install it?"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text("No"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Closes the dialog box
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text("Yes"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Closes the dialog box
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => UpdateCheckPage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
// check is new version is available
|
||||
if (await _apiProvider.checkAppVersion()) {
|
||||
// Display the update message
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text("New version available"),
|
||||
content: Text(
|
||||
"A new version is available. Would you like to install it?"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text("No"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Closes the dialog box
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text("Yes"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Closes the dialog box
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => UpdateCheckPage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SigninPage()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue