Commit 3a7c5384 authored by Ishini Kiridena's avatar Ishini Kiridena

Practitioner registration UI completed.

parent 667b5afb
......@@ -10,11 +10,11 @@ const { generateKeyPairSync } = require("crypto");
let timestamp;
router.post("/", async (req, res) => {
// const decryptedUserName = DecryptWithServerKey(req.body.username);
// const password = req.body.password;
// const decryptedEmail = DecryptWithServerKey(req.body.email);
// const decryptedWorkspace = DecryptWithServerKey(req.body.workspace);
// const decryptedFullName = DecryptWithServerKey(req.body.fullName);
const decryptedUserName = DecryptWithServerKey(req.body.username);
const password = req.body.password;
const decryptedEmail = DecryptWithServerKey(req.body.email);
const decryptedFullName = DecryptWithServerKey(req.body.fullName);
const decryptedWorkspace = DecryptWithServerKey(req.body.workspace);
//get the server key pair
const serverSourceKeyPair = StellarSDK.Keypair.fromSecret(
......@@ -99,11 +99,11 @@ router.post("/", async (req, res) => {
);
//create the practitioner object
const practitionerObj = new Practitioner({
username: req.body.username,
password: req.body.password,
email: req.body.email,
fullname: req.body.fullName,
workspace: req.body.workspace,
username: decryptedUserName,
password: password,
email: decryptedEmail,
fullname: decryptedFullName,
workspace: decryptedWorkspace,
rsakey: b64RSApk,
publickey: userKeyPair.publicKey(),
timestamp: timestamp,
......
......@@ -18,6 +18,7 @@ import PatientConsentForm from "./components/patientscreens/consent";
import PatientMainChatView from "./components/patientscreens/patientMainChatView";
import PatientAllPractitioners from "./components/patientscreens/allPractitioners";
import PatientNFTRequests from "./components/patientscreens/nftRequests";
import PractitionerRegistration from "./components/practitionerscreens/registration";
const Stack = createStackNavigator();
......@@ -111,6 +112,10 @@ export default function App() {
name="PatientNFTRequests"
component={PatientNFTRequests}
/>
<Stack.Screen
name="PractitionerRegistration"
component={PractitionerRegistration}
/>
</Stack.Navigator>
) : (
<SplashScreenComponent />
......
import { useNavigation } from "@react-navigation/core";
import { View, TextInput, Button, StyleSheet, Alert } from "react-native";
import React, { useState } from "react";
import EncryptWithServerKey from "../../services/encryptByServerKey";
import { LOCALBACKEND } from "../../env";
import DecryptWithServerKey from "../../services/decryptByServerKey";
import AsyncStorage from "@react-native-async-storage/async-storage";
export default function PractitionerRegistration() {
const navigation = useNavigation();
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [email, setEmail] = useState("");
const [fullName, setFullName] = useState("");
const [workspace, setWorkspace] = useState("");
const handleNext = async () => {
//encrypt the data
const encryptedUsername = EncryptWithServerKey(username);
const encryptedPassword = EncryptWithServerKey(password);
const encryptedEmail = EncryptWithServerKey(email);
const encryptedFullName = EncryptWithServerKey(fullName);
const encryptedWorkplace = EncryptWithServerKey(workspace);
//create JSON object
const registerObject = {
username: encryptedUsername,
password: encryptedPassword,
email: encryptedEmail,
fullName: encryptedFullName,
workspace: encryptedWorkplace,
};
const registerUrl = LOCALBACKEND + `/practitioner/register`;
try {
const regResponse = await fetch(registerUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(registerObject),
});
const responseData = await regResponse.json();
const { message, hash, pubkey, seed, rsapk, rsask } = responseData;
//Decrypt the data
const decryptedStellarPublicKey = DecryptWithServerKey(pubkey);
const decryptedStellarSecretKey = DecryptWithServerKey(seed);
const decryptedRsaPublicKey = DecryptWithServerKey(rsapk);
const decryptedRsaSecretKey = DecryptWithServerKey(rsask);
//save in the async storage
try {
await AsyncStorage.setItem(
"practitionerStellarPublicKey",
decryptedStellarPublicKey
);
await AsyncStorage.setItem(
"practitionerStellarSecretKey",
decryptedStellarSecretKey
);
await AsyncStorage.setItem(
"practitionerRsaPublicKey",
decryptedRsaPublicKey
);
await AsyncStorage.setItem(
"practitionerRsaSecretKey",
decryptedRsaSecretKey
);
const alertMessage =
`Public key : ` +
decryptedStellarPublicKey +
`\nSecret key : ` +
decryptedStellarSecretKey +
`\n Save the keys in a safe place`;
Alert.alert("Account keys", alertMessage, [
{
text: "Copy",
onPress: () => {},
},
{
text: "Close",
style: "cancel",
onPress: () => {
navigation.navigate("PatientMainChatView");
},
},
]);
} catch (errorWhenStoringInTheAsyncStorage) {
console.log(
"Error when saving details in the async storage : ",
errorWhenStoringInTheAsyncStorage
);
}
} catch (errorWhenRegisteringPractitioner) {
console.log(
"Error when registering practitioner : ",
errorWhenRegisteringPractitioner
);
}
};
return (
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder="User name"
value={username}
onChangeText={(text) => setUsername(text)}
/>
<TextInput
style={styles.input}
placeholder="Password"
value={password}
onChangeText={(text) => setPassword(text)}
secureTextEntry={true}
/>
<TextInput
style={styles.input}
placeholder="Full Name"
value={fullName}
onChangeText={(text) => setFullName(text)}
/>
<TextInput
style={styles.input}
placeholder="Workspace"
value={workspace}
onChangeText={(text) => setWorkspace(text)}
/>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={(text) => setEmail(text)}
/>
<Button title="Register" onPress={handleNext} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
input: {
width: "80%",
height: 40,
marginVertical: 10,
paddingHorizontal: 10,
borderColor: "gray",
borderWidth: 1,
borderRadius: 5,
},
});
......@@ -15,7 +15,10 @@ export default function SharedRegisterScreen({ navigation }) {
<View style={styles.separator} />
<Button
title="Practitioner Register"
onPress={() => console.log("Practitioner Register")}
onPress={() => {
console.log("PractitionerRegistration");
navigation.navigate("PractitionerRegistration");
}}
/>
</View>
</View>
......
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