From 48add2bc548a65c5fcd08b4fa91f57b2a65f5ac6 Mon Sep 17 00:00:00 2001 From: milan Date: Wed, 15 Nov 2023 10:17:13 +0530 Subject: [PATCH] Add: #191 - Individual ID in the register request --- android/app/build.gradle | 2 +- .../io/igrant/data4diabetes/MainActivity.kt | 21 ++++++ .../controllers/dataAgreement_controller.dart | 3 +- .../otp/controllers/otp_controller.dart | 8 ++- .../controllers/register_controller.dart | 66 ++++++++++++------- lib/app/my_app.dart | 2 - 6 files changed, 75 insertions(+), 27 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 2171f15..f05c6ca 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -136,7 +136,7 @@ dependencies { implementation platform('com.google.firebase:firebase-bom:28.0.1') implementation 'com.google.firebase:firebase-dynamic-links-ktx' // implementation 'com.github.L3-iGrant:mobileSDK-android:2.5.2' - implementation 'com.github.decentralised-dataexchange:bb-consent-android-privacy-dashboard:2023.11.5' + implementation 'com.github.decentralised-dataexchange:bb-consent-android-privacy-dashboard:2023.11.6' implementation 'com.github.zcweng:switch-button:0.0.3@aar' implementation 'com.cocosw:bottomsheet:1.5.0' implementation 'com.github.markomilos:paginate:1.0.0' diff --git a/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt b/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt index c26f0b5..1473d62 100644 --- a/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt +++ b/android/app/src/main/kotlin/io/igrant/data4diabetes/MainActivity.kt @@ -173,6 +173,27 @@ class MainActivity : FlutterActivity() { PrivacyDashboard.showDataAgreementPolicy() .withDataAgreement(dataAgreementResponse ?: "").withLocale("en").start(this) } + "CreateIndividual" -> { + val apiKey: String? = call.argument("apiKey") + val baseUrl: String? = call.argument("baseUrl") + var data: String? = null + GlobalScope.launch { + data = PrivacyDashboard.createAnIndividual( + baseUrl = baseUrl ?: "", + apiKey = apiKey ?: "", + ) + if (data != null) { + result.success(data) + } else { + result.error( + "GetDataAgreement error", + "Error occurred. Data: $data", + null + ) + } + + } + } } } diff --git a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart index f0f8058..cab8fd4 100644 --- a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart +++ b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart @@ -70,10 +70,11 @@ class DataAgreementContoller extends BaseController { SharedPreferences _prefs = await SharedPreferences.getInstance(); await _prefs.setString('dataSharingAccessToken', accessToken!); + var userId = _prefs.getString('privacyDashboarduserId'); try { var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": PrivacyDashboard().userId, + "userId": userId??PrivacyDashboard().userId, "dataAgreementID": PrivacyDashboard().registrationDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); diff --git a/lib/app/modules/otp/controllers/otp_controller.dart b/lib/app/modules/otp/controllers/otp_controller.dart index 63058c3..bc8ce1b 100644 --- a/lib/app/modules/otp/controllers/otp_controller.dart +++ b/lib/app/modules/otp/controllers/otp_controller.dart @@ -6,6 +6,7 @@ import 'package:Data4Diabetes/app/modules/login/controllers/login_controller.dar import 'package:Data4Diabetes/app/network/exceptions/api_exception.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../../../data/model/login/LoginRequest.dart'; import '../../../data/model/login/LoginResponse.dart'; @@ -22,6 +23,7 @@ class OtpController extends BaseController { final UserRepositoryImpl _impl = UserRepositoryImpl(); final PreferenceManagerImpl _preferenceManagerImpl = PreferenceManagerImpl(); final int statusCode = 200; + void verifyOTP() async { showLoading(); VerifyOtpRequest request = VerifyOtpRequest( @@ -31,6 +33,8 @@ class OtpController extends BaseController { VerifyOtpResponse response = await _impl.verifyOTP(request); if (response.token != null) { _preferenceManagerImpl.setString('token', response.token); + SharedPreferences _prefs = await SharedPreferences.getInstance(); + _prefs.setString('privacyDashboarduserId', response.lastname); hideLoading(); verifyOtpController.clear(); Get.offAll(MainView()); @@ -74,9 +78,11 @@ class OtpController extends BaseController { "shared Register firstname:" + registerController.shareFirstName.value); debugPrint( "shared Register lastname:" + registerController.shareLastName.value); + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var userId = _prefs.getString('privacyDashboarduserId'); RegisterRequest request = RegisterRequest( firstname: registerController.shareFirstName.value, - lastname: registerController.shareLastName.value, + lastname: userId, mobile_number: registerController.sharePhoneNumber.value); try { RegisterResponse response = await _impl.register(request); diff --git a/lib/app/modules/register/controllers/register_controller.dart b/lib/app/modules/register/controllers/register_controller.dart index 2e36bca..bf7a626 100644 --- a/lib/app/modules/register/controllers/register_controller.dart +++ b/lib/app/modules/register/controllers/register_controller.dart @@ -61,9 +61,11 @@ class RegisterController extends BaseController { void registerUser() async { try { + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": PrivacyDashboard().userId, + "userId": userId??PrivacyDashboard().userId, "dataAgreementID": PrivacyDashboard().backupAndRestoreDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); @@ -77,7 +79,7 @@ class RegisterController extends BaseController { sharePhoneNumber.value = isdCode! + mobileNumberController.text; RegisterRequest request = RegisterRequest( firstname: firstNameController.text, - lastname: "no last name", + lastname: userId, mobile_number: isdCode! + mobileNumberController.text); try { RegisterResponse response = await _impl.register(request); @@ -172,23 +174,25 @@ class RegisterController extends BaseController { hideLoading(); } } - onSkipTap()async{ - try { - getDataAgreement(sharingtoken:accessToken,sharingDataAgreementID:PrivacyDashboard().backupAndRestoreDataAgreementId,isFlag:true); - // Handle success - int index = selectedPage.value + 1; - pageController.animateToPage( - index, - duration: const Duration(milliseconds: 500), - curve: Curves.ease, - ); - - } catch (e) { - GetSnackToast(message: e.toString()); - } + onSkipTap() async { + try { + getDataAgreement( + sharingtoken: accessToken, + sharingDataAgreementID: + PrivacyDashboard().backupAndRestoreDataAgreementId, + isFlag: true); + // Handle success + int index = selectedPage.value + 1; + pageController.animateToPage( + index, + duration: const Duration(milliseconds: 500), + curve: Curves.ease, + ); + } catch (e) { + GetSnackToast(message: e.toString()); } - + } Future onNextButtonTap() async { String pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)'; @@ -205,6 +209,17 @@ class RegisterController extends BaseController { message: appLocalization.registerExistingUser, ); } else { + var response = await platform.invokeMethod('CreateIndividual', { + "apiKey": PrivacyDashboard().apiKey, + "baseUrl": "${PrivacyDashboard().baseUrl}/" + }); + + Map responseMap = json.decode(response); + Map individual = responseMap['individual']; + String? id = individual['id']; + SharedPreferences _prefs = await SharedPreferences.getInstance(); + _prefs.setString('privacyDashboarduserId', id ?? ""); + Get.to(DataAgreementView()); } } @@ -332,10 +347,12 @@ class RegisterController extends BaseController { // // } onAgreeButtonTap() async { - try { + try { + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": PrivacyDashboard().userId, + "userId": userId??PrivacyDashboard().userId, "dataAgreementID": PrivacyDashboard().donateYourDataDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); @@ -343,7 +360,8 @@ class RegisterController extends BaseController { if (responseMap['optIn'] == true) { getDataAgreement( sharingtoken: accessToken, - sharingDataAgreementID: PrivacyDashboard().backupAndRestoreDataAgreementId, + sharingDataAgreementID: + PrivacyDashboard().backupAndRestoreDataAgreementId, isFlag: true); // Handle success int index = selectedPage.value + 1; @@ -365,9 +383,11 @@ class RegisterController extends BaseController { required String? sharingDataAgreementID, bool? isFlag}) async { try { + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreement', { "apiKey": PrivacyDashboard().apiKey, - "userId": PrivacyDashboard().userId, + "userId": userId??PrivacyDashboard().userId, "dataAgreementID": sharingDataAgreementID, "baseUrl": PrivacyDashboard().baseUrl }); @@ -407,9 +427,11 @@ class RegisterController extends BaseController { getDataAgreementWithApiKey({required String? sharingDataAgreementID}) async { try { + SharedPreferences _prefs = await SharedPreferences.getInstance(); + var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreementWithApiKey', { "apiKey": PrivacyDashboard().apiKey, - "userId": PrivacyDashboard().userId, + "userId": userId??PrivacyDashboard().userId, "dataAgreementID": sharingDataAgreementID, "baseUrl": PrivacyDashboard().baseUrl }); diff --git a/lib/app/my_app.dart b/lib/app/my_app.dart index 03c7a10..d4dee96 100644 --- a/lib/app/my_app.dart +++ b/lib/app/my_app.dart @@ -106,9 +106,7 @@ class _MyAppState extends State { SharedPreferences _prefs = await SharedPreferences.getInstance(); if (_prefs.getString('privacyDashboardApiKey') == null) { _prefs.setString('privacyDashboardApiKey', PrivacyDashboard().apiKey); - _prefs.setString('privacyDashboardorgId', "64f09f778e5f3800014a879a"); _prefs.setString('privacyDashboardbaseUrl', PrivacyDashboard().baseUrl); - _prefs.setString('privacyDashboarduserId', PrivacyDashboard().userId); } } }