From da1851fc03b4485f5411b4a68d584e402320a2ca Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 16 Aug 2014 09:39:08 +0900 Subject: [PATCH] tidy up --- src/ninki-api.js | 6 ++-- src/ninki-engine.js | 51 +++++++++++++++------------ src/ninki-ui.js | 84 +++++++++++++++++++++++++++++++++------------ 3 files changed, 95 insertions(+), 46 deletions(-) diff --git a/src/ninki-api.js b/src/ninki-api.js index ef9f38b..445f6cf 100644 --- a/src/ninki-api.js +++ b/src/ninki-api.js @@ -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 { diff --git a/src/ninki-engine.js b/src/ninki-engine.js index 1ea14b4..cd99383 100644 --- a/src/ninki-engine.js +++ b/src/ninki-engine.js @@ -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) { @@ -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) { @@ -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 @@ -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); @@ -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, @@ -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, @@ -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 @@ -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; diff --git a/src/ninki-ui.js b/src/ninki-ui.js index be7c070..50a7fd4 100644 --- a/src/ninki-ui.js +++ b/src/ninki-ui.js @@ -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 () { @@ -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(); @@ -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(); }); @@ -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(); @@ -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'); @@ -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) {