Commit 0e4155f8 authored by Ishini Kiridena's avatar Ishini Kiridena

registration backend call completed

parent facaecd6
...@@ -5,6 +5,8 @@ import RadioForm, { ...@@ -5,6 +5,8 @@ import RadioForm, {
RadioButtonInput, RadioButtonInput,
RadioButtonLabel, RadioButtonLabel,
} from "react-native-simple-radio-button"; } from "react-native-simple-radio-button";
import EncryptWithServerKey from "../../../services/encryptByServerKey";
import { LOCALBACKEND } from "../../../env";
export default function PatientRegEight({ navigation, route }) { export default function PatientRegEight({ navigation, route }) {
const [educationLevel, setEducationLevel] = useState(""); const [educationLevel, setEducationLevel] = useState("");
...@@ -23,9 +25,79 @@ export default function PatientRegEight({ navigation, route }) { ...@@ -23,9 +25,79 @@ export default function PatientRegEight({ navigation, route }) {
{ label: "Self Employed", value: "Self Employed" }, { label: "Self Employed", value: "Self Employed" },
]; ];
const handleSave = () => { const handleSave = async () => {
//call the method for registration //encrypt the data
console.log(route.params, educationLevel, employedStatus); const encryptedEmail = EncryptWithServerKey(route.params.email);
const encryptedUsername = EncryptWithServerKey(route.params.username);
const encryptedPassword = EncryptWithServerKey(route.params.password);
const encryptedName = EncryptWithServerKey(route.params.name);
const encryptedPronoun = EncryptWithServerKey(route.params.pronoun);
const encryptedStringDate = EncryptWithServerKey(route.params.stringDate);
const encryptedGender = EncryptWithServerKey(route.params.gender);
const encryptedOrphan = EncryptWithServerKey(route.params.orphan);
const encryptedSiblingCount = EncryptWithServerKey(
route.params.siblingCount
);
const encryptedRelationshipStatus = EncryptWithServerKey(
route.params.relationshipStatus
);
const encryptedNumberOfChildren = EncryptWithServerKey(
route.params.numberOfChildren
);
const encryptedSexualPreference = EncryptWithServerKey(
route.params.sexualPreference
);
const encryptedEthnicity = EncryptWithServerKey(route.params.ethnicity);
const encryptedReligion = EncryptWithServerKey(route.params.religion);
const encryptedNationality = EncryptWithServerKey(route.params.nationality);
const encryptedEducationLevel = EncryptWithServerKey(
route.params.educationLevel
);
const encryptedEmployedStatus = EncryptWithServerKey(
route.params.employedStatus
);
//create JSON object
const regObject = {
email: encryptedEmail,
username: encryptedUsername,
password: encryptedPassword,
name: encryptedName,
pronoun: encryptedPronoun,
birthday: encryptedStringDate,
gender: encryptedGender,
orphan: encryptedOrphan,
siblingcount: encryptedSiblingCount,
relationship: encryptedRelationshipStatus,
childcount: encryptedNumberOfChildren,
sexualpreference: encryptedSexualPreference,
religion: encryptedReligion,
ethnicity: encryptedEthnicity,
nationality: encryptedNationality,
educationlevel: encryptedEducationLevel,
employed: encryptedEmployedStatus,
};
const registerUrl = LOCALBACKEND + `/patient/register`;
//call the backend endpoint
try {
const regResponse = await fetch(registerUrl, {
method: "POST",
body: JSON.stringify(regObject),
});
console.log(regResponse);
const responseData = await regResponse.json();
if (regResponse.ok) {
console.log("Success", responseData);
} else {
console.log(responseData);
}
} catch (errorWhenSendingRegObj) {
console.error("Error : ", errorWhenSendingRegObj);
}
}; };
return ( return (
......
export const AES_KEY = "QfTjWnZr4u7x!A%D";
export const LOCALBACKEND = "http://192.168.8.117:4000";
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"expo-status-bar": "~1.4.4", "expo-status-bar": "~1.4.4",
"react": "18.2.0", "react": "18.2.0",
"react-native": "0.71.7", "react-native": "0.71.7",
"react-native-crypto-js": "^1.0.0",
"react-native-datepicker": "^1.7.2", "react-native-datepicker": "^1.7.2",
"react-native-simple-radio-button": "^2.7.4" "react-native-simple-radio-button": "^2.7.4"
}, },
...@@ -11222,6 +11223,11 @@ ...@@ -11222,6 +11223,11 @@
"nullthrows": "^1.1.1" "nullthrows": "^1.1.1"
} }
}, },
"node_modules/react-native-crypto-js": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/react-native-crypto-js/-/react-native-crypto-js-1.0.0.tgz",
"integrity": "sha512-FNbLuG/HAdapQoybeZSoes1PWdOj0w242gb+e1R0hicf3Gyj/Mf8M9NaED2AnXVOX01b2FXomwUiw1xP1K+8sA=="
},
"node_modules/react-native-datepicker": { "node_modules/react-native-datepicker": {
"version": "1.7.2", "version": "1.7.2",
"resolved": "https://registry.npmjs.org/react-native-datepicker/-/react-native-datepicker-1.7.2.tgz", "resolved": "https://registry.npmjs.org/react-native-datepicker/-/react-native-datepicker-1.7.2.tgz",
...@@ -21883,6 +21889,11 @@ ...@@ -21883,6 +21889,11 @@
"nullthrows": "^1.1.1" "nullthrows": "^1.1.1"
} }
}, },
"react-native-crypto-js": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/react-native-crypto-js/-/react-native-crypto-js-1.0.0.tgz",
"integrity": "sha512-FNbLuG/HAdapQoybeZSoes1PWdOj0w242gb+e1R0hicf3Gyj/Mf8M9NaED2AnXVOX01b2FXomwUiw1xP1K+8sA=="
},
"react-native-datepicker": { "react-native-datepicker": {
"version": "1.7.2", "version": "1.7.2",
"resolved": "https://registry.npmjs.org/react-native-datepicker/-/react-native-datepicker-1.7.2.tgz", "resolved": "https://registry.npmjs.org/react-native-datepicker/-/react-native-datepicker-1.7.2.tgz",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"expo-status-bar": "~1.4.4", "expo-status-bar": "~1.4.4",
"react": "18.2.0", "react": "18.2.0",
"react-native": "0.71.7", "react-native": "0.71.7",
"react-native-crypto-js": "^1.0.0",
"react-native-datepicker": "^1.7.2", "react-native-datepicker": "^1.7.2",
"react-native-simple-radio-button": "^2.7.4" "react-native-simple-radio-button": "^2.7.4"
}, },
......
import CryptoJS from "react-native-crypto-js";
import { useEffect } from "react";
import { AES_KEY } from "../env";
function EncryptWithServerKey(originalTxt) {
const key = CryptoJS.enc.Utf8.parse(AES_KEY);
const options = {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
iv: CryptoJS.enc.Utf8.parse(AES_KEY),
};
const encryptedTxt = CryptoJS.AES.encrypt(
originalTxt,
key,
options
).toString();
return encryptedTxt;
}
export default EncryptWithServerKey;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment