Skip to content

Commit

Permalink
Release 0.1.7 mobile Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Administrator committed Mar 8, 2015
1 parent 7383e2c commit aaa71d1
Show file tree
Hide file tree
Showing 5 changed files with 3,529 additions and 1,349 deletions.
84 changes: 80 additions & 4 deletions src/ninki-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ function lpost(url, postData, callback) {

req.end();



} else {

$.ajax({
Expand Down Expand Up @@ -205,10 +203,10 @@ function lpost(url, postData, callback) {
}
//return callback(true, data.statusText);
} else {
location.reload();
//location.reload();
}
} else {

return callback(true, sanitizer.sanitize(data.statusText));
}


Expand Down Expand Up @@ -573,6 +571,41 @@ API.getTransactionRecords = function (guid, sharedid, callback) {

};

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

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

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

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

});

};

API.getTransactionsForNetwork = function (guid, sharedid, username, callback) {

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

lpost("/api/1/u/gettransactionsfornetwork", 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 All @@ -591,6 +624,24 @@ API.getInvoiceList = function (guid, sharedid, callback) {

};

API.getInvoicesToPayNetwork = function (guid, sharedid, username, callback) {

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

lpost("/api/1/u/getinvoicestopaynetwork", postData, function (err, invoices) {

if (!err) {
var jtran = JSON.parse(invoices);

return callback(err, jtran);
} else {
return callback(err, invoices);
}

});

};

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

var postData = { guid: guid, sharedid: sharedid };
Expand All @@ -608,6 +659,23 @@ API.getInvoiceByUserList = function (guid, sharedid, callback) {

};

API.getInvoicesByUserNetwork = function (guid, sharedid, username, callback) {

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

lpost("/api/1/u/getinvoicesbyusernetwork", postData, function (err, invoices) {

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

});

};



API.updateInvoice = function (guid, sharedid, username, invoiceId, transactionId, status, callback) {
Expand Down Expand Up @@ -681,6 +749,14 @@ API.getDeviceToken = function (guid, sharedid, deviceName, twoFactorCode, callba
});
};

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




API.getRecoveryPacket = function (guid, callback) {
Expand Down
133 changes: 133 additions & 0 deletions src/ninki-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,139 @@ function Device() {
}
}




this.setSecureStorageObject = setSecureStorageObject;
function setSecureStorageObject(cname, cvalue, key, encryptor, expiry) {


if (isChromeApp()) {

var encp = encryptor(cvalue, key);
var ptok = {};
ptok.ct = encp.toString();
ptok.iv = encp.iv.toString();

if (expiry) {
ptok.date = new Date();
ptok.expiry = expiry;
}

var ptoken = JSON.stringify(ptok);

var obj = {};
obj[cname] = ptoken

chrome.storage.local.set(obj, function () {

console.log("saved");

});

}
else {

var encp = encryptor(cvalue, key);
var ptok = {};
ptok.ct = encp.toString();
ptok.iv = encp.iv.toString();

if (expiry) {
ptok.date = new Date();
ptok.expiry = expiry;
}

var ptoken = JSON.stringify(ptok);
localStorage.setItem(cname, ptoken);

}


}


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

if (isChromeApp()) {

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

result = result[cname];

if (result != "") {
var decryptok = true;
var datac = "";
try {

var enc = JSON.parse(result);

if (enc.date) {
if (enc.expiry) {
var currentdate = new Date();
if (((new Date) - new Date(enc.date)) < enc.expiry) {
datac = decryptor(enc.ct, key, enc.iv);
}
}
} else {
datac = decryptor(enc.ct, key, enc.iv);
}

} catch (error) {
decryptok = false;
}

}

return callback(result);

});

} else {

if (localStorage.getItem(cname)) {

result = localStorage.getItem(cname);

if (result != "") {
var decryptok = true;
var datac = "";
try {
var enc = JSON.parse(result);

if (enc.date) {
if (enc.expiry) {
var currentdate = new Date();
if (((new Date) - new Date(enc.date)) < enc.expiry) {
datac = decryptor(enc.ct, key, enc.iv);
}
}
} else {
datac = decryptor(enc.ct, key, enc.iv);
}

} catch (error) {
decryptok = false;
}

if (decryptok) {
result = datac;
}

}

return callback(result);

} else {
return callback('');
}

}

}


}

module.exports = Device;
Loading

0 comments on commit aaa71d1

Please sign in to comment.