Skip to content

Commit

Permalink
Feature: #239- Create Individual user Id from developer options by pa…
Browse files Browse the repository at this point in the history
…ssing apiKey and baseUrl
  • Loading branch information
lijogeorgep authored and josmilan committed Dec 6, 2023
1 parent 929f941 commit 7c018fd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 64 deletions.
1 change: 0 additions & 1 deletion lib/app/Constants/privacy_dashboard.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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
Expand All @@ -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<String, dynamic> responseMap = json.decode(response);
Map<String, dynamic> 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<String> 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();
},
),
],
);
},
);

}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<FormState> formKey = GlobalKey<FormState>();
final _validate = false.obs;
@override
Expand Down Expand Up @@ -63,15 +65,14 @@ class PrivacyDashboardCredentialView
const Divider(),
// _orgIdWidget(),
// const Divider(),
_userIdWidget(),
],
),
),
),
const SizedBox(
height: 20,
),
_buttonSet(),
_buttonSet(context),
],
),
),
Expand Down Expand Up @@ -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<Color>(AppColors.colorAccent),
MaterialStateProperty.all<Color>(AppColors.colorAccent),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radiusConst),
))),
borderRadius: BorderRadius.circular(radiusConst),
))),
onPressed: () async {
_validate.value = _privacyDashboardCredentialController
.apiKeyController.text.isEmpty;
Expand All @@ -236,17 +205,17 @@ class PrivacyDashboardCredentialView
));
}

_resetButton() {
_resetButton(BuildContext context) {
return ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(AppColors.colorAccent),
MaterialStateProperty.all<Color>(AppColors.colorAccent),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radiusConst),
))),
borderRadius: BorderRadius.circular(radiusConst),
))),
onPressed: () async {
_privacyDashboardCredentialController.resetButtonAction();
_privacyDashboardCredentialController.resetButtonAction(context);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
Expand All @@ -258,11 +227,11 @@ class PrivacyDashboardCredentialView
));
}

_buttonSet() {
_buttonSet(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_resetButton(),
_resetButton(context),
_submitButton(),
],
);
Expand Down
8 changes: 4 additions & 4 deletions lib/app/modules/register/controllers/register_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down

0 comments on commit 7c018fd

Please sign in to comment.