Skip to content

Commit

Permalink
Add: #191 - Individual ID in the register request
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan authored and lijogeorgep committed Nov 15, 2023
1 parent 705e12a commit 48add2b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
8 changes: 7 additions & 1 deletion lib/app/modules/otp/controllers/otp_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
66 changes: 44 additions & 22 deletions lib/app/modules/register/controllers/register_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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);
Expand Down Expand Up @@ -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<void> onNextButtonTap() async {
String pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)';
Expand All @@ -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<String, dynamic> responseMap = json.decode(response);
Map<String, dynamic> individual = responseMap['individual'];
String? id = individual['id'];
SharedPreferences _prefs = await SharedPreferences.getInstance();
_prefs.setString('privacyDashboarduserId', id ?? "");

Get.to(DataAgreementView());
}
}
Expand Down Expand Up @@ -332,18 +347,21 @@ 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
});
Map<String, dynamic> responseMap = json.decode(response);
if (responseMap['optIn'] == true) {
getDataAgreement(
sharingtoken: accessToken,
sharingDataAgreementID: PrivacyDashboard().backupAndRestoreDataAgreementId,
sharingDataAgreementID:
PrivacyDashboard().backupAndRestoreDataAgreementId,
isFlag: true);
// Handle success
int index = selectedPage.value + 1;
Expand All @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down
2 changes: 0 additions & 2 deletions lib/app/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ class _MyAppState extends State<MyApp> {
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);
}
}
}

0 comments on commit 48add2b

Please sign in to comment.