Skip to content

Commit

Permalink
Chrome App Release v1.3
Browse files Browse the repository at this point in the history
changes for chrome app release
  • Loading branch information
Administrator committed May 8, 2015
1 parent aaa71d1 commit fa0886d
Show file tree
Hide file tree
Showing 9 changed files with 8,555 additions and 1,432 deletions.
219 changes: 159 additions & 60 deletions src/ninki-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,91 +135,91 @@ function lpost(url, postData, callback) {

} else {

$.ajax({
url: "https://api.ninkip2p.com" + url,
type: "POST",
timeout: 10000,
data: JSON.stringify(postData),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: { 'api-token': apiToken },
success: function (data) {

data = sanitizer.sanitize(data);

var jdata = JSON.parse(data);

if (jdata.error) {
return callback(true, jdata.message);
}
if (!(typeof jdata.message === "undefined")) {
$.ajax({
url: "https://api.ninkip2p.com:443" + url,
type: "POST",
timeout: 10000,
data: JSON.stringify(postData),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: { 'api-token': apiToken },
success: function (data) {

data = sanitizer.sanitize(data);

var jdata = JSON.parse(data);

if (jdata.error) {
return callback(true, jdata.message);
}
if (!(typeof jdata.message === "undefined")) {

return callback(false, jdata.message);
return callback(false, jdata.message);

}
}

return callback(false, JSON.stringify(jdata));
},
fail: function (data, textStatus) {
return callback(false, JSON.stringify(jdata));
},
fail: function (data, textStatus) {

data = sanitizer.sanitize(data);
textStatus = sanitizer.sanitize(textStatus);
data = sanitizer.sanitize(data);
textStatus = sanitizer.sanitize(textStatus);

return callback(true, {
textStatus: textStatus,
data: data
});
},
error: function (data) {
return callback(true, {
textStatus: textStatus,
data: data
});
},
error: function (data) {

if (data.statusText == "timeout") {
if (data.statusText == "timeout") {

return callback(true, "Could not connect to the Ninki server. Please try again. If the problem persists email [email protected].");
return callback(true, "Could not connect to the Ninki server. Please try again. If the problem persists email [email protected].");

}
}


if (data.status == 0) {
if (data.status == 0) {

return callback(true, "Could not connect to the network. Please check that you are connected to the internet.");
return callback(true, "Could not connect to the network. Please check that you are connected to the internet.");

}
}

if (data.status == 403) {
//session has been lost
if (data.status == 403) {
//session has been lost

} else if (data.status == 401) {
} else if (data.status == 401) {

if (!window.cordova) {
if (chrome) {
if (chrome.runtime) {
if (chrome.runtime.reload) {
chrome.runtime.reload()
if (!window.cordova) {
if (chrome) {
if (chrome.runtime) {
if (chrome.runtime.reload) {
chrome.runtime.reload()
} else {
location.reload();
}
} else {
location.reload();
}
//return callback(true, data.statusText);
} else {
location.reload();
//location.reload();
}
//return callback(true, data.statusText);
} else {
//location.reload();
return callback(true, sanitizer.sanitize(data.statusText));
}
} else {
return callback(true, sanitizer.sanitize(data.statusText));
}


} else {
} else {

data.responseText = sanitizer.sanitize(data.responseText);
data.responseText = sanitizer.sanitize(data.responseText);

return callback(true, data.responseText);
}
return callback(true, data.responseText);
}


}
});
}
});

}
}
Expand All @@ -246,7 +246,7 @@ API.getMasterPublicKeyFromUpstreamServer = function (guid, callback) {


var postData = { guid: guid };
return lpost("/api/1/u/createaccount", postData, function (err, response) {
return lpost("/api/2/u/createaccount", postData, function (err, response) {

if (err) {
return callback(err, response);
Expand All @@ -266,6 +266,10 @@ API.getMasterPublicKeyFromUpstreamServer = function (guid, callback) {
});
};





//function doesUsernameExist
//verifies that the requested username does not already exist on our database
API.doesAccountExist = function (username, email, callback) {
Expand Down Expand Up @@ -606,6 +610,23 @@ API.getTransactionsForNetwork = function (guid, sharedid, username, callback) {
};


API.getTimeline = function (guid, sharedid, callback) {

var postData = { guid: guid, sharedid: sharedid };

lpost("/api/1/u/gettimeline", postData, function (err, transactions) {

if (!err) {
var jtran = JSON.parse(transactions);
return callback(err, jtran);
} else {
return callback(err, transactions);
}

});

};

API.getInvoiceList = function (guid, sharedid, callback) {

var postData = { guid: guid, sharedid: sharedid };
Expand Down Expand Up @@ -701,7 +722,7 @@ API.registerDevice = function (guid, deviceName, deviceId, deviceModel, devicePI

API.getDeviceKey = function (guid, devicePIN, regToken, callback) {
var postData = { guid: guid, devicePIN: devicePIN, regToken: regToken };
return lpost("/api/1/u/getdevicekey", postData, function (err, dataStr) {
return lpost("/api/2/u/getdevicekey", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};
Expand Down Expand Up @@ -750,7 +771,7 @@ API.getDeviceToken = function (guid, sharedid, deviceName, twoFactorCode, callba
};

API.getDeviceTokenForApp = function (guid, sharedid, deviceName, callback) {
var postData = { guid: guid, sharedid: sharedid, deviceName: deviceName};
var postData = { guid: guid, sharedid: sharedid, deviceName: deviceName };
return lpost("/api/1/u/getdevicetokenforapp", postData, function (err, dataStr) {
return callback(err, dataStr);
});
Expand Down Expand Up @@ -781,4 +802,82 @@ API.createBackupCodes = function (guid, sharedid, twoFactorCode, callback) {
};


API.updateEmailAddress = function (guid, sharedid, emailAddress, callback) {
var postData = { guid: guid, sharedid: sharedid, emailAddress: emailAddress };
return lpost("/api/1/u/updateemailaddress", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};


API.createAccountSecPub = function (guid, sharedid, secretPub, callback) {
var postData = { guid: guid, sharedid: sharedid, secretPub: secretPub };
return lpost("/api/1/u/createaccountsecpub", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};

API.getAccountSecPub = function (guid, sharedid, callback) {
var postData = { guid: guid, sharedid: sharedid};
return lpost("/api/1/u/getaccountsecpub", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};

API.removeAccountSecPub = function (guid, sharedid, callback) {
var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/removeaccountsecpub", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};

API.getGUIDByMPKH = function (mpkh, callback) {
var postData = { mpkh: mpkh };
return lpost("/api/1/getguidbympkh", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};


API.requestAuthMigration = function (guid, secret, authreqtoken, callback) {
var postData = { guid: guid, secret: secret, authreqtoken: authreqtoken };
return lpost("/api/1/u/requestauthmigration", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};

API.getAuthMigrationRequest = function (guid, secret, callback) {
var postData = { guid: guid, secret: secret};
return lpost("/api/1/u/getauthmigrationrequest", postData, function (err, dataStr) {

if (!err) {
var jtran = JSON.parse(dataStr);
return callback(err, jtran);
} else {
return callback(err, dataStr);
}

});
};

API.authMigration = function (guid, sharedid, twoFactorToken, authreqtoken, callback) {
var postData = { guid: guid, sharedid: sharedid, twoFactorToken: twoFactorToken, authreqtoken: authreqtoken };
return lpost("/api/1/u/authmigration", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};

///

API.getAuthMigrationToken = function (guid, secret, authreqtoken, callback) {
var postData = { guid: guid, secret: secret, authreqtoken: authreqtoken };
return lpost("/api/1/u/getauthmigrationtoken", postData, function (err, dataStr) {
return callback(err, dataStr);
});
};

//



module.exports = API;
27 changes: 20 additions & 7 deletions src/ninki-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function Device() {

if (typeof window.cordova === 'undefined') {

//switch to false for mob
return true;

} else {
Expand Down Expand Up @@ -232,15 +233,15 @@ function Device() {


this.getSecureStorageObject = getSecureStorageObject;
function getSecureStorageObject(cname, key, decryptor, callback) {
function getSecureStorageObject(cname, key, decryptor, asbytes, callback) {

if (isChromeApp()) {

chrome.storage.local.get(cname, function (result) {

result = result[cname];

if (result != "") {
if (!(typeof result === 'undefined')) {
var decryptok = true;
var datac = "";
try {
Expand All @@ -251,20 +252,31 @@ function Device() {
if (enc.expiry) {
var currentdate = new Date();
if (((new Date) - new Date(enc.date)) < enc.expiry) {
datac = decryptor(enc.ct, key, enc.iv);
datac = decryptor(enc.ct, key, enc.iv, asbytes);
}
}
} else {
datac = decryptor(enc.ct, key, enc.iv);
datac = decryptor(enc.ct, key, enc.iv, asbytes);

}

} catch (error) {
decryptok = false;
}

result = "";
if (decryptok) {
result = datac;
}
return callback(result);

} else {

return callback("");

}

return callback(result);


});

Expand All @@ -284,17 +296,18 @@ function Device() {
if (enc.expiry) {
var currentdate = new Date();
if (((new Date) - new Date(enc.date)) < enc.expiry) {
datac = decryptor(enc.ct, key, enc.iv);
datac = decryptor(enc.ct, key, enc.iv, asbytes);
}
}
} else {
datac = decryptor(enc.ct, key, enc.iv);
datac = decryptor(enc.ct, key, enc.iv, asbytes);
}

} catch (error) {
decryptok = false;
}

result = "";
if (decryptok) {
result = datac;
}
Expand Down
Loading

0 comments on commit fa0886d

Please sign in to comment.