Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
Administrator committed Aug 16, 2014
1 parent 33138dc commit da1851f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/ninki-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ API.getMasterPublicKeyFromUpstreamServer = function (guid, callback) {

//function doesUsernameExist
//verifies that the requested username does not already exist on our database
API.doesUsernameExist = function (username, callback) {
API.doesAccountExist = function (username,email, callback) {

var postData = { username: username };
var postData = { username: username, email:email };

lpost("/api/1/u/doesusernameexist", postData, function (err, response) {
lpost("/api/1/u/doesaccountexist", postData, function (err, response) {
if (err) {
return callback(err, response);
} else {
Expand Down
51 changes: 30 additions & 21 deletions src/ninki-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ function Engine() {
//assert(element, "Element not specified");
element.val(uuid.v4());
}

//function encrypt (valueToEncrypt, passphrase) {
// return encrypt(valueToEncrypt, passphrase);
//}

this.getguid = getguid;
function getguid() {
//assert(element, "Element not specified");
return uuid.v4();
}


this.encrypt = encrypt;
function encrypt(valueToEncrypt, passphrase) {
Expand All @@ -64,14 +67,9 @@ function Engine() {

var encrypted = CryptoJS.AES.encrypt(valueToEncrypt, key, { iv: ivwords });

//var test = encrypted.iv.toString();

return encrypted;
};

//function decrypt (encryptedObj, passphrase, iv) {
// return decrypt(encryptedObj, passphrase, iv);
//}

this.decrypt = decrypt;
function decrypt(encryptedObj, passphrase, iv) {
Expand Down Expand Up @@ -104,16 +102,22 @@ function Engine() {


//check if the username already exists
API.doesUsernameExist(username.toLowerCase(), function (err, usernameExistsOnServer) {
API.doesAccountExist(username.toLowerCase(), emailAddress.toLowerCase(), function (err, accExists) {

if (usernameExistsOnServer) {
if (accExists.UserExists) {

return callback(true, "ErrUserExists");

} else {
}
else if (accExists.EmailExists) {

return callback(true, "ErrEmailExists");

}
else {


//stretch the password with the local guid as an IV
//stretch the password with the local guid as a salt
m_this.m_password = CryptoJS.PBKDF2(password, m_this.m_oguid, {
keySize: 256 / 32,
iterations: 1000
Expand Down Expand Up @@ -220,9 +224,6 @@ function Engine() {
iterations: 1000
}).toString();

//TODO: Move this out of here
//if the provided password is not stretched


try {
var walletInformation = decrypt(wallet.Payload, m_this.m_password, wallet.IV);
Expand Down Expand Up @@ -368,7 +369,7 @@ function Engine() {


//save the wallet keys and user token in an encrypted packet
//AES256 using PBKDF2 on the password and a unique IV
//AES256 using PBKDF2 on the password and a unique salt

var wal = {
coldPub: coldPub,
Expand All @@ -381,10 +382,10 @@ function Engine() {

m_this.m_walletinfo = wal;

var encryptedPayload = encrypt(wal, m_this.m_password, m_this.m_oguid);
var encryptedPayload = encrypt(wal, m_this.m_password);

//save the PGP keys in an encrypted packet
//AES256 using PBKDF2 on the password and a unique IV
//AES256 using PBKDF2 on the password and a unique salt

var encryptedUserPayload = encrypt({
RSAPriv: keypair.privateKeyArmored,
Expand All @@ -397,7 +398,7 @@ function Engine() {
//knows their password without having to hold any
//information about their password (for future use)
var secret = Bitcoin.Crypto.SHA256(userToken).toString();
var encryptedSecret = encrypt(secret, m_this.m_password, m_this.m_oguid);
var encryptedSecret = encrypt(secret, m_this.m_password);


//create a packet to post to the server
Expand Down Expand Up @@ -1985,7 +1986,15 @@ function Engine() {

this.doesUsernameExist = doesUsernameExist;
function doesUsernameExist(username, callback) {
API.doesUsernameExist(username, callback);
API.doesAccountExist(username, '', function (err, accExists) {

if (err) {
callback(err, accExists);
} else {
callback(err, accExists.UserExists);
}

});
}

this.sendWelcomeDetails = sendWelcomeDetails;
Expand Down
84 changes: 62 additions & 22 deletions src/ninki-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ function UI() {
}


function getLocalTime(datetime) {

var timestamp = datetime,
t = new Date(datetime),
hours = t.getHours(),
min = t.getMinutes() + '',
pm = false,
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

if (hours > 11) {
hours = hours - 12;
pm = true;
}

if (hours == 0) hours = 12;
if (min.length == 1) min = '0' + min;

return (hours + ':' + min + ' ' + (pm ? 'pm' : 'am'));

}

jQuery(document).ready(function () {


Expand Down Expand Up @@ -136,6 +157,15 @@ function UI() {
});



$('#frmSaveTwoFactor').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});


$(document).on("keydown", function (e) {
if (e.which === 8 && !$(e.target).is("input, textarea")) {
e.preventDefault();
Expand All @@ -155,6 +185,25 @@ function UI() {
});


//if (getCookie('guid').length == 0) {

var betafrom = 'December 12, 2009 12:00 pm GMT';
var betato = 'December 12, 2009 01:00 pm GMT';

betafrom = getLocalTime(betafrom);
betato = getLocalTime(betato);

$('#betafrom').html(betafrom);
$('#betato').html(betato);

$('#basicModal').modal('show');

$("#btnDeclineBeta").click(function () {
window.location.href = '/'
});
//}


$("#btncreatewallet").click(function () {
showCreateWalletStart();
});
Expand Down Expand Up @@ -284,6 +333,19 @@ function UI() {
$("#btnCreate").removeClass('disabled');
$("#lnkOpenWallet").show();
}
if (result == "ErrEmailExists") {

$("#createWalletStart input#emailaddress").css("border-color", "#ffaaaa");
$("#imgcreatewaiting").hide();

$("#createwalletalert").show();
$("#createwalletalertmessage").html("The email address is already in use");

$("#btnCreate").prop('disabled', false);
$("#btnCreate").removeClass('disabled');
$("#lnkOpenWallet").show();
}

if (result == "ErrCreateAccount") {

$("#imgcreatewaiting").hide();
Expand Down Expand Up @@ -2108,17 +2170,6 @@ function UI() {
$('#Email').val(settingsObject['Email']);
$('#EmailNotification').prop('checked', settingsObject['EmailNotification']);

$('#TwoFactor').val(settingsObject['TwoFactor']);
$('#AutoEmailBackup').val(settingsObject['AutoEmailBackup']);
$('#EmailVerified').val(settingsObject['EmailVerified']);
$('#Phone').val(settingsObject['Phone']);
$('#PhoneVerified').val(settingsObject['PhoneVerified']);
$('#Language').val(settingsObject['Language']);
$('#LocalCurrency').val(settingsObject['LocalCurrency']);
$('#PhoneNotification').val(settingsObject['PhoneNotification']);
$('#PasswordHint').val(settingsObject['PasswordHint']);
$('#TwoFactorType').val(settingsObject['TwoFactorType']);


if (settingsObject['CoinUnit'] == 'BTC') {
$('#cuSelected').html('BTC');
Expand Down Expand Up @@ -2160,17 +2211,6 @@ function UI() {

jsonPacket['Email'] = $('#Email').val();
jsonPacket['EmailNotification'] = $('#EmailNotification').checked;
jsonPacket['TwoFactor'] = $('#TwoFactor').val();
jsonPacket['AutoEmailBackup'] = $('#AutoEmailBackup').val();
jsonPacket['EmailVerified'] = $('#EmailVerified').val();
jsonPacket['Phone'] = $('#Phone').val();
jsonPacket['PhoneVerified'] = $('#PhoneVerified').val();
jsonPacket['Language'] = $('#Language').val();
jsonPacket['LocalCurrency'] = $('#LocalCurrency').val();
jsonPacket['PhoneNotification'] = $('#PhoneNotification').val();
jsonPacket['PasswordHint'] = $('#PasswordHint').val();
jsonPacket['TwoFactorType'] = $('#TwoFactorType').val();


Engine.updateAccountSettings(jsonPacket, $("#txtTwoFactorCodeForSettings").val(), function (err, response) {
if (err) {
Expand Down

0 comments on commit da1851f

Please sign in to comment.