120 lines
3 KiB
JavaScript
120 lines
3 KiB
JavaScript
// Generated by CoffeeScript 2.3.0
|
|
(function() {
|
|
var createSecret, dataNotFound, hashLoad, initBinds, newSecret, requestSecret, secretCreated, securePassword, showData, somethingWrong;
|
|
|
|
securePassword = null;
|
|
|
|
createSecret = function() {
|
|
var secret;
|
|
secret = $('#formCreateSecret').find('textarea').val();
|
|
securePassword = Math.random().toString(36).substring(2);
|
|
secret = GibberishAES.enc(secret, securePassword);
|
|
$.ajax('api/create', {
|
|
data: {
|
|
secret: secret
|
|
},
|
|
dataType: "json",
|
|
statusCode: {
|
|
201: secretCreated,
|
|
400: somethingWrong,
|
|
500: somethingWrong,
|
|
404: function() {
|
|
// Mock for interface testing
|
|
return secretCreated({
|
|
secret_id: 'foobar'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
dataNotFound = function() {
|
|
return $('#notfound').show();
|
|
};
|
|
|
|
hashLoad = function() {
|
|
var hash;
|
|
hash = window.location.hash;
|
|
if (hash.length === 0) {
|
|
return;
|
|
}
|
|
$('#cardNewSecret').hide();
|
|
$('#cardSecretURL').hide();
|
|
$('#notfound').hide();
|
|
$('#somethingwrong').hide();
|
|
return $('#cardReadSecretPre').show();
|
|
};
|
|
|
|
requestSecret = function() {
|
|
var hash, id, parts;
|
|
hash = window.location.hash;
|
|
hash = decodeURIComponent(hash);
|
|
parts = hash.split('|');
|
|
if (parts.length === 2) {
|
|
hash = parts[0];
|
|
securePassword = parts[1];
|
|
}
|
|
id = hash.substring(1);
|
|
return $.ajax(`api/get/${id}`, {
|
|
dataType: "json",
|
|
statusCode: {
|
|
404: dataNotFound,
|
|
200: showData
|
|
}
|
|
});
|
|
};
|
|
|
|
initBinds = function() {
|
|
$('#formCreateSecret').bind('submit', createSecret);
|
|
$('#newSecret, .navbar-brand').bind('click', newSecret);
|
|
$(window).bind('hashchange', hashLoad);
|
|
return $('#revealSecret').bind('click', requestSecret);
|
|
};
|
|
|
|
newSecret = function() {
|
|
location.href = location.href.split('#')[0];
|
|
return false;
|
|
};
|
|
|
|
secretCreated = function(data) {
|
|
var secretHash, url;
|
|
secretHash = data.secret_id;
|
|
if (securePassword !== null) {
|
|
secretHash = `${secretHash}|${securePassword}`;
|
|
}
|
|
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();
|
|
return securePassword = null;
|
|
};
|
|
|
|
showData = function(data) {
|
|
var secret;
|
|
secret = data.secret;
|
|
if (securePassword !== null) {
|
|
secret = GibberishAES.dec(secret, securePassword);
|
|
}
|
|
$('#cardNewSecret').hide();
|
|
$('#cardSecretURL').hide();
|
|
$('#notfound').hide();
|
|
$('#somethingwrong').hide();
|
|
$('#cardReadSecretPre').hide();
|
|
$('#cardReadSecret').show();
|
|
return $('#cardReadSecret').find('textarea').val(secret);
|
|
};
|
|
|
|
somethingWrong = function() {
|
|
return $('#somethingwrong').show();
|
|
};
|
|
|
|
$(function() {
|
|
initBinds();
|
|
return hashLoad();
|
|
});
|
|
|
|
}).call(this);
|