diff --git a/lib/app/Constants/privacy_dashboard.dart b/lib/app/Constants/privacy_dashboard.dart index 5506368..b1bbb80 100644 --- a/lib/app/Constants/privacy_dashboard.dart +++ b/lib/app/Constants/privacy_dashboard.dart @@ -1,6 +1,5 @@ class PrivacyDashboard{ var apiKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY0ZjA5Zjc3OGU1ZjM4MDAwMTRhODc5YSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTBhZTFmYmJlMWViNDAwMDE3MTFkODciLCJleHAiOjE3MDI1NzUwNTV9.ZCEzLanCmsbEoThyGV2xAuGju48NyHaCUPU1y3tLnGg'; - var userId = '6553af58ec660dae93f6e254'; var baseUrl = 'https://demo-consent-bb-api.igrant.io/v2'; var registrationDataAgreementId = '6553a34bec660dae93f6e0f0'; diff --git a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart index b1fd189..7693b74 100644 --- a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart +++ b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart @@ -65,7 +65,7 @@ class DataAgreementContoller extends BaseController { showLoading(); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId??PrivacyDashboard().userId, + "userId": userId, "dataAgreementID": PrivacyDashboard().registrationDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); diff --git a/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart b/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart index 683bec4..b451889 100644 --- a/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart +++ b/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart @@ -1,10 +1,15 @@ +import 'dart:convert'; + import 'package:Data4Diabetes/app/Constants/privacy_dashboard.dart'; import 'package:Data4Diabetes/app/core/base/base_controller.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../../launcher/views/launcher_view.dart'; + class PrivacyDashboardCredentialController extends BaseController { var platform = const MethodChannel('io.igrant.data4diabetes.channel'); @@ -24,7 +29,6 @@ class PrivacyDashboardCredentialController extends BaseController { var apiKey = _prefs.getString('privacyDashboardApiKey'); var orgId = _prefs.getString('privacyDashboardorgId'); var baseUrl = _prefs.getString('privacyDashboardbaseUrl'); - var userId = _prefs.getString('privacyDashboarduserId'); print('apikey now:$apiKey'); apiKey != null ? apiKeyController.text = apiKey @@ -35,35 +39,74 @@ class PrivacyDashboardCredentialController extends BaseController { baseUrl != null ? baseUrlController.text = baseUrl : baseUrlController.text = PrivacyDashboard().baseUrl; - userId != null - ? userIdController.text = userId - : userIdController.text = PrivacyDashboard().userId; print('apiKeyController.text${apiKeyController.text}'); } submitButtonAction() async { + var response = await platform.invokeMethod('CreateIndividual', { + "apiKey": apiKeyController.text, + "baseUrl": baseUrlController.text, + }); + Map responseMap = json.decode(response); + Map individual = responseMap['individual']; + String? id = individual['id']; SharedPreferences _prefs = await SharedPreferences.getInstance(); _prefs.setString('privacyDashboardApiKey', apiKeyController.text); _prefs.setString('privacyDashboardorgId', orgIdController.text); _prefs.setString('privacyDashboardbaseUrl', baseUrlController.text); - _prefs.setString('privacyDashboarduserId', userIdController.text); + _prefs.setString('privacyDashboarduserId', id ?? ""); Get.rawSnackbar( message: 'Updated : Close and Reopen the app to reflect the changes', backgroundColor: Colors.green); privacyDashboardCredentials(); } - resetButtonAction() async { + resetButtonAction(BuildContext context) async { SharedPreferences _prefs = await SharedPreferences.getInstance(); _prefs.setString('privacyDashboardApiKey', PrivacyDashboard().apiKey); _prefs.setString('privacyDashboardorgId', "64f09f778e5f3800014a879a"); _prefs.setString('privacyDashboardbaseUrl', PrivacyDashboard().baseUrl); - _prefs.setString('privacyDashboarduserId', PrivacyDashboard().userId); - privacyDashboardCredentials(); - Get.rawSnackbar( - message: - 'Success : Please logout and login, also reopen the app to reflect the changes', - backgroundColor: Colors.green); - privacyDashboardCredentials(); + _logout(context); + + } + + void _logout(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return CupertinoAlertDialog( + title: const Text('Alert'), + content: const Text('To reset privacy dashboard credentials you need to logout and login. Please confirm to continue'), + actions: [ + CupertinoDialogAction( + child: const Text('Logout'), + onPressed: () async { + privacyDashboardCredentials(); + Get.rawSnackbar( + message: + 'Updated : Close and Reopen the app to reflect the changes', + backgroundColor: Colors.green); + SharedPreferences _prefs = await SharedPreferences.getInstance(); + Set keys = _prefs.getKeys(); + + for (String key in keys) { + if (key != 'languageCode') { + await _prefs.remove(key); + } + } + Get.offAll(const LauncherView()); + }, + ), + CupertinoDialogAction( + child: const Text('Cancel'), + onPressed: () { + Get.back(); + }, + ), + ], + ); + }, + ); + } } diff --git a/lib/app/modules/developerOptions/views/privacy_dashboard_credential_view.dart b/lib/app/modules/developerOptions/views/privacy_dashboard_credential_view.dart index b291371..f3f942e 100644 --- a/lib/app/modules/developerOptions/views/privacy_dashboard_credential_view.dart +++ b/lib/app/modules/developerOptions/views/privacy_dashboard_credential_view.dart @@ -1,3 +1,5 @@ + + import 'package:Data4Diabetes/app/core/base/base_view.dart'; import 'package:flutter/material.dart'; import 'package:flutter/src/widgets/framework.dart'; @@ -16,7 +18,7 @@ class PrivacyDashboardCredentialView final double radiusConst = 18.0; final double fontSize = 16; final PrivacyDashboardCredentialController - _privacyDashboardCredentialController = Get.find(); + _privacyDashboardCredentialController = Get.find(); final GlobalKey formKey = GlobalKey(); final _validate = false.obs; @override @@ -63,7 +65,6 @@ class PrivacyDashboardCredentialView const Divider(), // _orgIdWidget(), // const Divider(), - _userIdWidget(), ], ), ), @@ -71,7 +72,7 @@ class PrivacyDashboardCredentialView const SizedBox( height: 20, ), - _buttonSet(), + _buttonSet(context), ], ), ), @@ -175,48 +176,16 @@ class PrivacyDashboardCredentialView ); } - _userIdWidget() { - return TextFormField( - validator: (value) { - if (value!.isEmpty) { - return 'Please enter a user Id'; - } - - return null; - }, - autofocus: false, - controller: _privacyDashboardCredentialController.userIdController, - decoration: const InputDecoration( - contentPadding: EdgeInsets.fromLTRB(16, 10, 0, 10), - label: Text('User ID'), - fillColor: Colors.transparent, - filled: true, - errorStyle: TextStyle(height: 0, color: Colors.red), - labelStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w400, - color: AppColors.silverAppBarOverlayColor, - fontStyle: FontStyle.italic, - ), - border: InputBorder.none, - focusedBorder: InputBorder.none, - enabledBorder: InputBorder.none, - errorBorder: InputBorder.none, - disabledBorder: InputBorder.none, - isDense: true, - ), - ); - } _submitButton() { return ElevatedButton( style: ButtonStyle( backgroundColor: - MaterialStateProperty.all(AppColors.colorAccent), + MaterialStateProperty.all(AppColors.colorAccent), shape: MaterialStateProperty.all( RoundedRectangleBorder( - borderRadius: BorderRadius.circular(radiusConst), - ))), + borderRadius: BorderRadius.circular(radiusConst), + ))), onPressed: () async { _validate.value = _privacyDashboardCredentialController .apiKeyController.text.isEmpty; @@ -236,17 +205,17 @@ class PrivacyDashboardCredentialView )); } - _resetButton() { + _resetButton(BuildContext context) { return ElevatedButton( style: ButtonStyle( backgroundColor: - MaterialStateProperty.all(AppColors.colorAccent), + MaterialStateProperty.all(AppColors.colorAccent), shape: MaterialStateProperty.all( RoundedRectangleBorder( - borderRadius: BorderRadius.circular(radiusConst), - ))), + borderRadius: BorderRadius.circular(radiusConst), + ))), onPressed: () async { - _privacyDashboardCredentialController.resetButtonAction(); + _privacyDashboardCredentialController.resetButtonAction(context); }, child: Padding( padding: const EdgeInsets.all(12.0), @@ -258,11 +227,11 @@ class PrivacyDashboardCredentialView )); } - _buttonSet() { + _buttonSet(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - _resetButton(), + _resetButton(context), _submitButton(), ], ); diff --git a/lib/app/modules/register/controllers/register_controller.dart b/lib/app/modules/register/controllers/register_controller.dart index 46e2c39..6806d08 100644 --- a/lib/app/modules/register/controllers/register_controller.dart +++ b/lib/app/modules/register/controllers/register_controller.dart @@ -65,7 +65,7 @@ class RegisterController extends BaseController { var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId ?? PrivacyDashboard().userId, + "userId": userId, "dataAgreementID": PrivacyDashboard().backupAndRestoreDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); @@ -236,7 +236,7 @@ class RegisterController extends BaseController { var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId ?? PrivacyDashboard().userId, + "userId": userId , "dataAgreementID": PrivacyDashboard().donateYourDataDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); @@ -274,7 +274,7 @@ class RegisterController extends BaseController { var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreement', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId ?? PrivacyDashboard().userId, + "userId": userId , "dataAgreementID": sharingDataAgreementID, "baseUrl": PrivacyDashboard().baseUrl }); @@ -320,7 +320,7 @@ class RegisterController extends BaseController { var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreementWithApiKey', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId ?? PrivacyDashboard().userId, + "userId": userId , "dataAgreementID": sharingDataAgreementID, "baseUrl": PrivacyDashboard().baseUrl });