Commit 6771b6f6 authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'update-the-patient-genesis' into 'master'

Changes added to the genesis of patient

See merge request !14
parents eab73446 b49cd585
......@@ -4,6 +4,7 @@ const DecryptWithServerKey = require("./../../services/decryptionservice");
const UserSchema = require("../../model/patient/patient");
const StellarSDK = require("stellar-sdk");
const PatientTransaction = require("../../model/stellar/transactionDetails");
const EncryptionService = require("./../../services/encryptionservice");
//Add user emotions to blockchain and transaction details to database
router.post("/", async (req, res) => {
......@@ -52,7 +53,7 @@ router.post("/", async (req, res) => {
.addOperation(
StellarSDK.Operation.manageData({
name: "Emotion",
value: emotion,
value: EncryptionService.EncryptWithStellarSeed(emotion, userSeed),
})
)
.addOperation(
......
......@@ -4,6 +4,7 @@ const DecryptWithServerKey = require("./../../services/decryptionservice");
const UserSchema = require("../../model/patient/patient");
const StellarSDK = require("stellar-sdk");
const PatientTransaction = require("../../model/stellar/transactionDetails");
const EncryptionService = require("./../../services/encryptionservice");
router.post("/", async (req, res) => {
// const userPubKey = DecryptWithServerKey(req.body.pubkey);
......@@ -52,7 +53,7 @@ router.post("/", async (req, res) => {
.addOperation(
StellarSDK.Operation.manageData({
name: "Mental state",
value: state,
value: EncryptionService.EncryptWithStellarSeed(state, userSeed),
})
)
.addOperation(
......
const express = require("express");
const router = express.Router();
const RegisterRequestSchema = require("./../../model/patient/registration");
require("dotenv").config();
const StellarSDK = require("stellar-sdk");
const DecryptWithServerKey = require("./../../services/decryptionservice");
......@@ -12,18 +11,23 @@ let timestamp;
router.post("/", async (req, res) => {
//decrypt user request details
//! @todo do not decrypt the password
const decryptedEmail = DecryptWithServerKey(req.body.email);
const decryptedPassword = DecryptWithServerKey(req.body.password);
const decryptedUserName = DecryptWithServerKey(req.body.email);
//catching the request
const request = new RegisterRequestSchema({
email: req.body.email,
username: req.body.username,
password: req.body.password,
});
console.log(request);
const decryptedEmail = req.body.email;
const decryptedPassword = req.body.password;
const decryptedUserName = req.body.username;
const decryptedName = req.body.name;
const decryptedPronoun = req.body.pronoun;
const decryptedBirthday = req.body.birthday;
const decryptedGender = req.body.gender;
const decryptedOrphan = req.body.orphan;
const decryptedSiblingCount = req.body.siblingcount;
const decryptedRelationship = req.body.relationship;
const decryptedChildCount = req.body.childcount;
const decryptedSexualPreference = req.body.sexualpreference;
const decryptedReligion = req.body.religion;
const decryptedEthnicity = req.body.ethnicity;
const decryptedNationality = req.body.nationality;
const decryptedEducationLevel = req.body.educationlevel;
const decryptedEmployed = req.body.employed;
//get the server key pair
const serverSourceKeyPair = StellarSDK.Keypair.fromSecret(
......@@ -48,7 +52,7 @@ router.post("/", async (req, res) => {
.addOperation(
StellarSDK.Operation.createAccount({
destination: userKeyPair.publicKey(),
startingBalance: "10",
startingBalance: "100",
})
)
.setTimeout(30)
......@@ -83,20 +87,6 @@ router.post("/", async (req, res) => {
"Account creation details saved in the database " + saveInCollection
);
//encrypt user entered details with stellar seed
const encEmail = EncryptionService.EncryptWithStellarSeed(
request.email,
userKeyPair.secret()
);
const encUsername = EncryptionService.EncryptWithStellarSeed(
request.username,
userKeyPair.secret()
);
const encPassword = EncryptionService.EncryptWithStellarSeed(
request.password,
userKeyPair.secret()
);
//get the user keypair
const userSourceKeyPair = StellarSDK.Keypair.fromSecret(
userKeyPair.secret()
......@@ -118,19 +108,136 @@ router.post("/", async (req, res) => {
.addOperation(
StellarSDK.Operation.manageData({
name: "Email Address",
value: encEmail,
value: EncryptionService.EncryptWithStellarSeed(
decryptedEmail,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Name",
value: EncryptionService.EncryptWithStellarSeed(
decryptedName,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Pronouns",
value: EncryptionService.EncryptWithStellarSeed(
decryptedPronoun,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Birthday",
value: EncryptionService.EncryptWithStellarSeed(
decryptedBirthday,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Gender",
value: EncryptionService.EncryptWithStellarSeed(
decryptedGender,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Orphan",
value: EncryptionService.EncryptWithStellarSeed(
decryptedOrphan,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Sibling Count",
value: EncryptionService.EncryptWithStellarSeed(
decryptedSiblingCount,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Relationship Status",
value: EncryptionService.EncryptWithStellarSeed(
decryptedRelationship,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Child Count",
value: EncryptionService.EncryptWithStellarSeed(
decryptedChildCount,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Sexual Preference",
value: EncryptionService.EncryptWithStellarSeed(
decryptedSexualPreference,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Religion",
value: EncryptionService.EncryptWithStellarSeed(
decryptedReligion,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Ethnicity",
value: EncryptionService.EncryptWithStellarSeed(
decryptedEthnicity,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Username",
value: encUsername,
name: "Nationality",
value: EncryptionService.EncryptWithStellarSeed(
decryptedNationality,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Previous",
value: "",
name: "Education level",
value: EncryptionService.EncryptWithStellarSeed(
decryptedEducationLevel,
userKeyPair.secret()
),
})
)
.addOperation(
StellarSDK.Operation.manageData({
name: "Employed",
value: EncryptionService.EncryptWithStellarSeed(
decryptedEmployed,
userKeyPair.secret()
),
})
)
.setTimeout(30)
......@@ -156,9 +263,9 @@ router.post("/", async (req, res) => {
console.log(new Date());
//create the user collection object to be added to the DB
const userCollectionObject = new UserSchema({
username: req.body.username,
username: decryptedUserName,
password: req.body.password,
email: req.body.email,
email: decryptedEmail,
publickey: userKeyPair.publicKey(),
genesishash: genesisTxnResult.hash,
currenthash: genesisTxnResult.hash,
......
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