2018-05-05 15:34:13 +00:00
|
|
|
// Generated by CoffeeScript 2.3.0
|
2017-08-03 16:32:30 +00:00
|
|
|
(function() {
|
2017-08-19 13:49:15 +00:00
|
|
|
var createSecret, dataNotFound, hashLoad, initBinds, newSecret, requestSecret, secretCreated, securePassword, showData, somethingWrong;
|
2017-08-03 16:32:30 +00:00
|
|
|
|
|
|
|
securePassword = null;
|
|
|
|
|
|
|
|
createSecret = function() {
|
|
|
|
var secret;
|
|
|
|
secret = $('#formCreateSecret').find('textarea').val();
|
2017-08-04 13:17:30 +00:00
|
|
|
securePassword = Math.random().toString(36).substring(2);
|
|
|
|
secret = GibberishAES.enc(secret, securePassword);
|
2017-08-03 16:32:30 +00:00
|
|
|
$.ajax('api/create', {
|
|
|
|
data: {
|
|
|
|
secret: secret
|
|
|
|
},
|
|
|
|
dataType: "json",
|
|
|
|
statusCode: {
|
|
|
|
201: secretCreated,
|
|
|
|
400: somethingWrong,
|
|
|
|
500: somethingWrong,
|
|
|
|
404: function() {
|
2018-05-05 15:34:13 +00:00
|
|
|
// Mock for interface testing
|
2017-08-03 16:32:30 +00:00
|
|
|
return secretCreated({
|
|
|
|
secret_id: 'foobar'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
dataNotFound = function() {
|
|
|
|
return $('#notfound').show();
|
|
|
|
};
|
|
|
|
|
|
|
|
hashLoad = function() {
|
2017-08-19 13:49:15 +00:00
|
|
|
var hash;
|
2017-08-03 16:32:30 +00:00
|
|
|
hash = window.location.hash;
|
|
|
|
if (hash.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-05 15:34:13 +00:00
|
|
|
$('#cardNewSecret').hide();
|
|
|
|
$('#cardSecretURL').hide();
|
2017-08-19 13:49:15 +00:00
|
|
|
$('#notfound').hide();
|
|
|
|
$('#somethingwrong').hide();
|
2018-05-05 15:34:13 +00:00
|
|
|
return $('#cardReadSecretPre').show();
|
2017-08-19 13:49:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
requestSecret = function() {
|
|
|
|
var hash, id, parts;
|
|
|
|
hash = window.location.hash;
|
2017-08-03 19:43:37 +00:00
|
|
|
hash = decodeURIComponent(hash);
|
2017-08-03 16:32:30 +00:00
|
|
|
parts = hash.split('|');
|
|
|
|
if (parts.length === 2) {
|
|
|
|
hash = parts[0];
|
|
|
|
securePassword = parts[1];
|
|
|
|
}
|
|
|
|
id = hash.substring(1);
|
2018-05-05 15:34:13 +00:00
|
|
|
return $.ajax(`api/get/${id}`, {
|
2017-08-03 16:32:30 +00:00
|
|
|
dataType: "json",
|
|
|
|
statusCode: {
|
|
|
|
404: dataNotFound,
|
|
|
|
200: showData
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
initBinds = function() {
|
|
|
|
$('#formCreateSecret').bind('submit', createSecret);
|
2017-08-03 18:01:22 +00:00
|
|
|
$('#newSecret, .navbar-brand').bind('click', newSecret);
|
2017-08-19 13:49:15 +00:00
|
|
|
$(window).bind('hashchange', hashLoad);
|
|
|
|
return $('#revealSecret').bind('click', requestSecret);
|
2017-08-03 16:32:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
newSecret = function() {
|
|
|
|
location.href = location.href.split('#')[0];
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
secretCreated = function(data) {
|
|
|
|
var secretHash, url;
|
|
|
|
secretHash = data.secret_id;
|
|
|
|
if (securePassword !== null) {
|
2018-05-05 15:34:13 +00:00
|
|
|
secretHash = `${secretHash}|${securePassword}`;
|
2017-08-03 16:32:30 +00:00
|
|
|
}
|
2018-05-05 15:34:13 +00:00
|
|
|
url = `${(location.href.split('#')[0])}#${secretHash}`;
|
|
|
|
$('#cardNewSecret').hide();
|
|
|
|
$('#cardReadSecretPre').hide();
|
|
|
|
$('#cardSecretURL').show();
|
|
|
|
$('#cardSecretURL').find('input').val(url);
|
|
|
|
$('#cardSecretURL').find('input').focus();
|
|
|
|
$('#cardSecretURL').find('input').select();
|
2017-08-03 18:01:22 +00:00
|
|
|
return securePassword = null;
|
2017-08-03 16:32:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
showData = function(data) {
|
|
|
|
var secret;
|
|
|
|
secret = data.secret;
|
|
|
|
if (securePassword !== null) {
|
|
|
|
secret = GibberishAES.dec(secret, securePassword);
|
|
|
|
}
|
2018-05-05 15:34:13 +00:00
|
|
|
$('#cardNewSecret').hide();
|
|
|
|
$('#cardSecretURL').hide();
|
2017-08-03 18:01:22 +00:00
|
|
|
$('#notfound').hide();
|
|
|
|
$('#somethingwrong').hide();
|
2018-05-05 15:34:13 +00:00
|
|
|
$('#cardReadSecretPre').hide();
|
|
|
|
$('#cardReadSecret').show();
|
|
|
|
return $('#cardReadSecret').find('textarea').val(secret);
|
2017-08-03 16:32:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
somethingWrong = function() {
|
|
|
|
return $('#somethingwrong').show();
|
|
|
|
};
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
initBinds();
|
|
|
|
return hashLoad();
|
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|