Commit 0b474514 authored by farhan-shahid's avatar farhan-shahid
Browse files

functionality complete

parent 996d93d0
......@@ -43,78 +43,63 @@ contract Federation {
//modifier to check if an employer has been registered with the federation
modifier onlyEmployer(address _employer) {
bool found = false;
if (employers[_employer]) {
found = true;
}
require(found == true);
require(checkEmployer(_employer));
_;
}
modifier onlyBank(address _bank) {
bool found = false;
if(checkBank(_bank) == true)
found = true;
require(found == true);
require(checkBank(_bank));
_;
}
modifier onlyHousingAuthority(address _housingAuthority) {
bool found = false;
if(checkHousingAuthority(_housingAuthority) == true)
found = true;
require(found == true);
require(checkHousingAuthority(_housingAuthority));
_;
}
modifier onlyInsuranceProvider(address _insuranceProvider) {
bool found = false;
if(checkInsuranceProvider(_insuranceProvider) == true)
found = true;
require(found == true);
require(checkInsuranceProvider(_insuranceProvider));
_;
}
modifier onlyPolice(address _police) {
require(checkPolice(_police));
_;
}
modifier only3rdParty(address _actor) {
bool found = false;
if(checkPolice(_police) == true)
if (checkEmployer(_actor))
found = true;
if(checkBank(_actor))
found = true;
if(checkHousingAuthority(_actor))
found = true;
if(checkInsuranceProvider(_actor))
found = true;
if(checkPolice(_actor))
found = true;
require(found == true);
_;
}
function checkEmployer(address _employer) public view returns (bool) {
if (employers[_employer]) {
return true;
}
return false;
return employers[_employer];
}
function checkBank(address _bank) public view returns (bool) {
if (banks[_bank]) {
return true;
}
return false;
return banks[_bank];
}
function checkHousingAuthority(address _housingAuthority) public view returns (bool) {
if (housingAuthorities[_housingAuthority]) {
return true;
}
return false;
return housingAuthorities[_housingAuthority];
}
function checkInsuranceProvider(address _insuranceProvider) public view returns (bool) {
if (insuranceProviders[_insuranceProvider]) {
return true;
}
return false;
return insuranceProviders[_insuranceProvider];
}
function checkPolice(address _police) public view returns (bool) {
if (polices[_police]) {
return true;
}
return false;
return polices[_police];
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ contract ProofOfEmployment is Federation {
federation = msg.sender;
}
function VerifyRequirement(string encryptedEmployee, string encryptedRequirement, string persona, address thirdParty, address landlord) public {
function RequestRequirementVerification(string encryptedEmployee, string encryptedRequirement, string persona, address thirdParty, address landlord) public {
if (compareStrings(persona, "employer")) {
require(checkEmployer(thirdParty));
} else if (compareStrings(persona, "bank")) {
......@@ -53,6 +53,10 @@ contract ProofOfEmployment is Federation {
emit verificationRequest(encryptedEmployee, encryptedRequirement, persona, thirdParty, landlord);
}
function VerifyRequirement(string encryptedEmployee, string encryptedResponse, address landlord) public only3rdParty(msg.sender) {
emit verificationResponse(encryptedEmployee, encryptedResponse, landlord);
}
//function for landlord to initiate data request
function VerifyData(address _employeeAddress) public {
......
......@@ -102,9 +102,13 @@ class Events extends Component {
} else if (propsEvents[i].event === 'verificationResponse' && propsEvents[i].returnValues.landlord === props.accounts[0]) {
var emp = decrypt(keyMappings[this.props.accounts[0].toLowerCase()].substr(2), propsEvents[i].returnValues[0]);
var resp = decrypt(keyMappings[this.props.accounts[0].toLowerCase()].substr(2), propsEvents[i].returnValues[1]);
var respObj = JSON.parse(resp);
console.log(respObj);
events.verificationResponse.push({
employee: emp,
resp: resp
response: respObj.response,
requirement: respObj.requirement,
persona: respObj.persona
});
}
}
......@@ -328,27 +332,27 @@ class Events extends Component {
console.log(pubKey);
var emp = encrypt(pubKey, event.employee);
var req = encrypt(pubKey, self.state.minSalary);
instance.VerifyRequirement(emp, req, 'employer', event.employer, account, { from: account });
instance.RequestRequirementVerification(emp, req, 'employer', event.employer, account, { from: account });
pubKey = util.privateToPublic(keyMappings[event.bank.toLowerCase()]);
req = encrypt(pubKey, self.state.minDeposit);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'bank', event.bank, account, { from: account });
instance.RequestRequirementVerification(emp, req, 'bank', event.bank, account, { from: account });
pubKey = util.privateToPublic(keyMappings[event.housingAuthority.toLowerCase()]);
req = encrypt(pubKey, self.state.changeFrequency);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'housingAuthority', event.housingAuthority, account, { from: account });
instance.RequestRequirementVerification(emp, req, 'housingAuthority', event.housingAuthority, account, { from: account });
pubKey = util.privateToPublic(keyMappings[event.insuranceProvider.toLowerCase()]);
req = encrypt(pubKey, self.state.minInsurance);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'insuranceProvider', event.insuranceProvider, account, { from: account });
instance.RequestRequirementVerification(emp, req, 'insuranceProvider', event.insuranceProvider, account, { from: account });
pubKey = util.privateToPublic(keyMappings[event.police.toLowerCase()]);
req = encrypt(pubKey, self.state.maxPolice);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'police', event.police, account, { from: account });
instance.RequestRequirementVerification(emp, req, 'police', event.police, account, { from: account });
});
};
......@@ -358,34 +362,26 @@ class Events extends Component {
if (error != null) console.log("Couldn't get accounts");
account = result[0];
});
let self = this;
getContract(this.context.drizzle).then(function(instance) {
var pubKey = util.privateToPublic(keyMappings[event.employer.toLowerCase()]);
console.log(pubKey);
var emp = encrypt(pubKey, event.employee);
var req = encrypt(pubKey, self.state.minSalary);
instance.VerifyRequirement(emp, req, 'employer', event.employer, { from: account });
pubKey = util.privateToPublic(keyMappings[event.bank.toLowerCase()]);
req = encrypt(pubKey, self.state.minDeposit);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'bank', event.bank, { from: account });
pubKey = util.privateToPublic(keyMappings[event.housingAuthority.toLowerCase()]);
req = encrypt(pubKey, self.state.changeFrequency);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'housingAuthority', event.housingAuthority, { from: account });
pubKey = util.privateToPublic(keyMappings[event.insuranceProvider.toLowerCase()]);
req = encrypt(pubKey, self.state.minInsurance);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'insuranceProvider', event.insuranceProvider, { from: account });
pubKey = util.privateToPublic(keyMappings[event.police.toLowerCase()]);
req = encrypt(pubKey, self.state.maxPolice);
emp = encrypt(pubKey, event.employee);
instance.VerifyRequirement(emp, req, 'police', event.police, { from: account });
});
getContract(this.context.drizzle)
.then(function(instance) {
var pubKey = util.privateToPublic(keyMappings[event.landlord.toLowerCase()]);
console.log(pubKey);
var emp = encrypt(pubKey, event.employee);
var resObj = {
response: verify,
requirement: event.req,
persona: event.persona
};
var res = encrypt(pubKey, JSON.stringify(resObj));
return instance.VerifyRequirement(emp, res, event.landlord, { from: account });
})
.then(function(result) {
alert('Request verified/refuted successfully! Transaction Hash: ' + result.tx);
console.log(result);
})
.catch(function(err) {
console.log(err.message);
});
};
render() {
......@@ -745,7 +741,7 @@ class Events extends Component {
</tr>
</thead>
{self.state.events.verificationRequest.map(function(event, i) {
if (event.persona === 'employer') {
if (event.persona === 'bank') {
return (
<tbody key={i}>
<tr>
......@@ -780,7 +776,7 @@ class Events extends Component {
</tr>
</thead>
{self.state.events.verificationRequest.map(function(event, i) {
if (event.persona === 'employer') {
if (event.persona === 'housingAuthority') {
return (
<tbody key={i}>
<tr>
......@@ -815,7 +811,7 @@ class Events extends Component {
</tr>
</thead>
{self.state.events.verificationRequest.map(function(event, i) {
if (event.persona === 'employer') {
if (event.persona === 'insuranceProvider') {
return (
<tbody key={i}>
<tr>
......@@ -850,7 +846,7 @@ class Events extends Component {
</tr>
</thead>
{self.state.events.verificationRequest.map(function(event, i) {
if (event.persona === 'employer') {
if (event.persona === 'police') {
return (
<tbody key={i}>
<tr>
......@@ -874,6 +870,40 @@ class Events extends Component {
</table>
</div>
)}
{role === 'Employee/Landlord' && (
<div>
<h5>Verification Responses</h5>
<table>
<thead>
<tr>
<th>Identity</th>
<th>3rd Party</th>
<th>Requirement</th>
<th>Response</th>
</tr>
</thead>
{self.state.events.verificationResponse.map(function(event, i) {
return (
<tbody key={i}>
<tr>
<td>
<Blockies seed={event.employee} size={10} scale={10} />
{event.employee}
</td>
<td>{event.persona}</td>
{event.persona === 'employer' && <td>Minimum Salary: {event.requirement}</td>}
{event.persona === 'bank' && <td>Minimum Deposit: {event.requirement}</td>}
{event.persona === 'housingAuthority' && <td>Maximum Change Frequency: {event.requirement}</td>}
{event.persona === 'insuranceProvider' && <td>Minimum Insurance: {event.requirement}</td>}
{event.persona === 'police' && <td>Maximum Police Cases: {event.requirement}</td>}
<td>{event.response ? '' : ''}</td>
</tr>
</tbody>
);
})}
</table>
</div>
)}
</div>
);
}
......
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