Skip to content

Commit

Permalink
Absolute path with baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
tameeshB committed Aug 26, 2017
1 parent 8def5f5 commit 5104975
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
11 changes: 7 additions & 4 deletions js/GroupKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
(function ($) {
// Jquery onload function.
$(document).ready(function(){
var baseURL = drupalSettings.client_side_file_crypto.baseURL;

/**
* Method to return the csrf token
*/
function getCsrfToken() {
return $.ajax({
type: "GET",
url: "/rest/session/token",
url: baseURL + "/rest/session/token",
async: false
}).responseText;
}

var routeName = drupalSettings.client_side_file_crypto.routeName;
if(routeName != 'client_side_file_crypto.newKeys')
$.get("/publicKey/?_format=json", function(xhr_pub_key){
$.get(baseURL + "/publicKey/?_format=json", function(xhr_pub_key){
var encrypt = new JSEncrypt();
encrypt.setPublicKey(xhr_pub_key['publicKey']);
$.get("/groupKeys?_format=json", function(pending_roles){
$.get(baseURL + "/groupKeys?_format=json", function(pending_roles){
var pending_role_names = pending_roles['roleNames'];
if(pending_role_names.length>0){
pending_role_names.forEach(function(role_name) {
Expand All @@ -30,7 +33,7 @@
"userID" : pending_roles['userID'],
};
jQuery.ajax({
url: '../accessKey/?_format=json',
url: baseURL + '/accessKey/?_format=json',
method: 'POST',
headers: {
'Content-Type': 'application/hal+json',
Expand Down
7 changes: 4 additions & 3 deletions js/decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

$(document).ready(function(){
var uid = drupalSettings.client_side_file_crypto.uid;
var baseURL = drupalSettings.client_side_file_crypto.baseURL;
var file = null;
var encryptedFileList = $(".node__content div[property='schema:text']");

//Method to return the csrf token.
function getCsrfToken() {
return $.ajax({
type: "GET",
url: "/rest/session/token",
url: baseURL + "/rest/session/token",
async: false
}).responseText;
}
Expand All @@ -20,7 +21,7 @@
function getAccessKey(roleName){
var xhrData = $.ajax({
type: "GET",
url: "/accessKey/?_format=json",
url: baseURL + "/accessKey/?_format=json",
async: false
}).responseText;
var accessKeysObject = JSON.parse(xhrData);
Expand Down Expand Up @@ -108,7 +109,7 @@

//Fetching the file list and appending to the DOM
if(nodeID != -1){
$.get("../fileMetadata/" + nodeID + "/?_format=json", function(fileMetaData){
$.get(baseURL + "/fileMetadata/" + nodeID + "/?_format=json", function(fileMetaData){
if(fileMetaData.fileCount != 0){
$(".node__content div[property='schema:text']").append("<h3 class='title'>Encrypted Files</h3>");
var files = fileMetaData.files;
Expand Down
11 changes: 6 additions & 5 deletions js/encrypt.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// Jquery wrapper for drupal to avoid conflicts between libraries.
(function ($) {
var baseURL = drupalSettings.client_side_file_crypto.baseURL;
/**
* Method to return the csrf token
*/
function getCsrfToken() {
return $.ajax({
type: "GET",
url: "/rest/session/token",
async: false
url: baseURL + "/rest/session/token",
async: false
}).responseText;
}

var file = undefined;
$(document).ready(function(){
$(".node-form").attr("action", "/node/add/"+$(".node-form").attr('data-drupal-selector').split("-")[1]);
$(".node-form").attr("action", "/node/add/" + $(".node-form").attr('data-drupal-selector').split("-")[1]);
var uid = drupalSettings.client_side_file_crypto.uid;
$("#cryptoFields").change(function(e){
e.preventDefault();
file = e.target.files[0];
var role = $("#roleSelect").val();
var fileName = "encrypted_" + file.name;
$.get("/accessKey/?_format=json", function(xhrAccessKey){
$.get(baseURL + "/accessKey/?_format=json", function(xhrAccessKey){
var privateKey = localStorage.getItem("csfcPrivKey_" + uid);
var decrypt = new JSEncrypt();
decrypt.setPrivateKey(privateKey);
Expand All @@ -37,7 +38,7 @@
formData.append('csfcRoleName', role);

$.ajax({
url: '/encryptedFileUpload',
url: baseURL + '/encryptedFileUpload',
data: formData,
processData: false,
contentType: false,
Expand Down
12 changes: 6 additions & 6 deletions js/pubkeyGen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Jquery wrapper for drupal to avoid conflicts between libraries.
(function ($) {
var baseURL = drupalSettings.client_side_file_crypto.baseURL;

// Jquery onload function.
function download(filename, text) {
Expand All @@ -22,7 +23,7 @@
function getCsrfToken() {
return $.ajax({
type: "GET",
url: "/rest/session/token",
url: baseURL + "/rest/session/token",
async: false
}).responseText;
}
Expand All @@ -31,7 +32,7 @@
function getPublicKey(uid){
var xhrData = $.ajax({
type: "GET",
url: "/publicKey/"+uid+"/?_format=json",
url: baseURL + "/publicKey/" + uid + "/?_format=json",
async: false
}).responseText;
var pubKeyObject = JSON.parse(xhrData);
Expand All @@ -40,7 +41,6 @@

$(document).ready(function(){
var uid = drupalSettings.client_side_file_crypto.uid;
var baseURL = drupalSettings.client_side_file_crypto.baseURL;
var ExistingPubKey = getPublicKey(uid);
if(!ExistingPubKey && !localStorage.getItem("csfcPrivKey_" + uid)){
//default pubkey size for now = 1024
Expand All @@ -57,7 +57,7 @@
};

jQuery.ajax({
url: '/publicKey?_format=json',
url: baseURL + '/publicKey?_format=json',
method: 'POST',
headers: {
'Content-Type': 'application/hal+json',
Expand All @@ -69,11 +69,11 @@
});
$("#key-status").text("Key generated.");
$("#more-info").text("A private key has been downloaded to your computer that you will need to keep to keep safe in case your browser data gets wiped and to access the encrypted files on other devices. In case you need to restore the keys you can do it at /restoreKeys");
$("#more-info").append("<br><font color='#FF0000'>Key requests have been put up for each of your roles.<br>You will only be able to access the encrypted features once another user with the keys logs in and generated keys for you.<br>You will need to wait until then. </font><br><a href='"+baseURL+"/user/keyGenRedirect'>Go to home.</a>");
$("#more-info").append("<br><font color='#FF0000'>Key requests have been put up for each of your roles.<br>You will only be able to access the encrypted features once another user with the keys logs in and generated keys for you.<br>You will need to wait until then. </font><br><a href='" +baseURL + "/user/keyGenRedirect'>Go to home.</a>");
download('PrivateKey.pem', privateKey);
} else {
$("#key-status").text("Key already generated!");
$("#more-info").html("A key pair has already been generated for this user.<br><a href='"+baseURL+"'>Go to home.</a>");
$("#more-info").html("A key pair has already been generated for this user.<br><a href='" + baseURL + "'>Go to home.</a>");
}
});
$(document).ajaxStop(function() {
Expand Down
8 changes: 4 additions & 4 deletions js/updatePendingKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
(function ($) {
// Jquery onload function.
$(document).ready(function(){
var baseURL = drupalSettings.client_side_file_crypto.baseURL;

/**
* Method to return the csrf token
*/
function getCsrfToken() {
return $.ajax({
type: "GET",
url: "/rest/session/token",
url: baseURL + "/rest/session/token",
async: false
}).responseText;
}

var uid = drupalSettings.client_side_file_crypto.uid;
var baseURL = drupalSettings.client_side_file_crypto.baseURL;
var routeName = drupalSettings.client_side_file_crypto.routeName;
var blockedRoutes = [
//'client_side_file_crypto.postLogin',
Expand All @@ -29,7 +29,7 @@
}
var privateKey = localStorage.getItem("csfcPrivKey_" + uid);
var encrypt = new JSEncrypt();
$.get("/accessKey/pending?_format=json", function(pendingKeysJSON){
$.get(baseURL + "/accessKey/pending?_format=json", function(pendingKeysJSON){
var decrypt = new JSEncrypt();
decrypt.setPrivateKey(privateKey);
pendingKeys = pendingKeysJSON['accessKeys'];
Expand All @@ -46,7 +46,7 @@
"userID" : accessKey['uid'],
};
jQuery.ajax({
url: '/accessKey/?_format=json',
url: baseURL + '/accessKey/?_format=json',
method: 'POST',
headers: {
'Content-Type': 'application/hal+json',
Expand Down

0 comments on commit 5104975

Please sign in to comment.