forked from loadmybowl/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract_sign_process.php
53 lines (38 loc) · 1.33 KB
/
contract_sign_process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
session_start();
ob_start();
require_once('check-login.php');
try {
include_once "config.php";
include_once "resources.php";
include_once "helperFunctions.php";
include_once "dbhelper.php";
$signerAddress = $_SESSION['address'];
$signerID = $_SESSION['user_name'];
if (isset($_GET['contractid'])) {
$contractID = $_GET['contractid'];
}
else {
throw new Exception("Invalid Contract ID", 1);
}
$dbHelper = new DBHelper(session_id(), $_SERVER);
if (!$dbHelper->isValidContract($contractID)) {
throw new Exception("Invalid Contract ID");
}
if (!$dbHelper->isAuthorizedToSignContract($_SESSION['address'], $contractID)) {
throw new Exception("You are not authorized to sign this contract");
}
if ($dbHelper->hasSignedTheContract($_SESSION['address'], $contractID)) {
throw new Exception("You have already signed this contract");
}
$contractDetails = $dbHelper->getContractDetails($contractID);
$fileHash = $contractDetails[Literals::CONTRACT_DETAILS_FIELD_NAMES['FILE_HASH']];
$signature = $dbHelper->signMessage($signerAddress, $fileHash);
$txID = $dbHelper->signContract($contractID, $signerID, $signerAddress, $signature);
echo "<h4 style='color:green'>Signed Successfully</h4>";
}
catch (Exception $e)
{
echo "<h3 style='color:red'>".$e->getMessage()."</h3>";
}
?>