added logout feature

This commit is contained in:
Abhishek Sinha 2020-05-28 14:19:41 +05:30
parent 8cc5b98afc
commit e4eb35dabd

View File

@ -285,6 +285,9 @@
<h3 id="user_type" class="light-text"> <h3 id="user_type" class="light-text">
User User
</h3> </h3>
<button id="logout_btn">
Sign Out
</button>
<button id="admin_panel_btn" class="hide"> <button id="admin_panel_btn" class="hide">
Admin Panel Admin Panel
</button> </button>
@ -12619,24 +12622,33 @@
return false; return false;
}, },
reset_flo_keys: () => { reset_flo_keys: async () => {
const promise1 = updateinDB( try {
"localbitcoinUser",
{
id: "00-01",
myLocalFLOAddress: "",
myLocalFLOPublicKey: "",
myAddressTrustLevel: 1
},
"00-01"
);
const promise2 = removeAllinDB("my_supernode_private_key_chunks"); if(!localbitcoinplusplus.master_configurations.supernodesPubKeys
const promise3 = removeAllinDB("myClosestSupernodes"); .includes(localbitcoinplusplus.wallets.my_local_flo_address)) {
return Promise.all([promise1, promise2, promise3]) await clearDatabase(db);
.then(() => true)
.catch(e => false); await updateinDB(
"localbitcoinUser",
{
id: "00-01",
myLocalFLOAddress: "",
myLocalFLOPublicKey: "",
myAddressTrustLevel: 1
},
"00-01"
);
BitBang();
return true;
}
} catch(e) {
notify(`Reset failed. Please refresh the page.`, 'error');
return false;
}
}, },
// https://stackoverflow.com/a/39538518/5348972 // https://stackoverflow.com/a/39538518/5348972
@ -14401,7 +14413,6 @@
} else { } else {
if (typeof conn_su_flo_id == "string") { if (typeof conn_su_flo_id == "string") {
my_local_data.lastConnectedTime = +new Date(); my_local_data.lastConnectedTime = +new Date();
my_local_data.lastConnectedSupernode = conn_su_flo_id;
updateinDB("localbitcoinUser", my_local_data); updateinDB("localbitcoinUser", my_local_data);
} else { } else {
mss = `WARNING: Failed to update current supernode connected status in localbitcoinUser.`; mss = `WARNING: Failed to update current supernode connected status in localbitcoinUser.`;
@ -15372,7 +15383,6 @@
showPopup('sign_in_popup', 'no'); showPopup('sign_in_popup', 'no');
async function app_login() { async function app_login() {
try { try {
const RM_WALLET = new localbitcoinplusplus.wallets(); const RM_WALLET = new localbitcoinplusplus.wallets();
let pk_manual = document.getElementById('get_priv_key_field').value; let pk_manual = document.getElementById('get_priv_key_field').value;
@ -15383,7 +15393,7 @@
&& usr_details.myLocalFLOAddress.length>0) { && usr_details.myLocalFLOAddress.length>0) {
if(gen_new_keys.address!==usr_details.myLocalFLOAddress) { if(gen_new_keys.address!==usr_details.myLocalFLOAddress) {
notify('Incorrect private key. Please provide your FLO private key to Sign in.', 'error'); notify('Incorrect private key. Please provide your FLO private key to Sign in.', 'error');
return resolve(false); return reject(false);
} }
} else { } else {
notify(`This is your LOGIN PRIVATE KEY: notify(`This is your LOGIN PRIVATE KEY:
@ -15437,10 +15447,10 @@
return resolve(gen_new_keys.privateKeyWIF); return resolve(gen_new_keys.privateKeyWIF);
} catch(e) { } catch(e) {
console.error(e);
notify('Incorrect private key. Please provide your FLO private key to Sign in.', 'error'); notify('Incorrect private key. Please provide your FLO private key to Sign in.', 'error');
return resolve(false); return false;
} }
} }
const signInBtn = document.getElementById('signInBtn'); const signInBtn = document.getElementById('signInBtn');
@ -28645,7 +28655,6 @@
myLocalFLOAddress: "", myLocalFLOAddress: "",
myLocalFLOPublicKey: "", myLocalFLOPublicKey: "",
myAddressTrustLevel: 1, myAddressTrustLevel: 1,
lastConnectedSupernode: "",
lastConnectedTime: "" lastConnectedTime: ""
}; };
@ -30091,8 +30100,6 @@
const localbitcoinuserdiv = document.getElementById("localbitcoinuserdiv"); const localbitcoinuserdiv = document.getElementById("localbitcoinuserdiv");
localbitcoinuserdiv.innerHTML = `${my_flo_id}`; localbitcoinuserdiv.innerHTML = `${my_flo_id}`;
// showMessage ->updating your balances
displayBalances(my_flo_id);
}); });
}; };
@ -30178,7 +30185,6 @@
typeof localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS == "string" typeof localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS == "string"
) { ) {
idbData.lastConnectedTime = +new Date(); idbData.lastConnectedTime = +new Date();
idbData.lastConnectedSupernode = localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS;
updateinDB("localbitcoinUser", idbData); updateinDB("localbitcoinUser", idbData);
} else { } else {
mss = `WARNING: Failed to update current supernode connected status in localbitcoinUser.`; mss = `WARNING: Failed to update current supernode connected status in localbitcoinUser.`;
@ -30206,7 +30212,6 @@
trader_flo_address: MY_LOCAL_FLO_ADDRESS trader_flo_address: MY_LOCAL_FLO_ADDRESS
} }
); );
console.log(addNewKNode);
doSend(addNewKNode); doSend(addNewKNode);
}); });
@ -30264,10 +30269,6 @@
} }
}); });
// Check last connected supernode, if not primary then
// update the user data from other su first
//wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed(idbData.myLocalFLOAddress);
// Show balances // Show balances
displayBalances(idbData.myLocalFLOAddress); displayBalances(idbData.myLocalFLOAddress);
@ -30289,6 +30290,10 @@
// Send Tx UI // Send Tx UI
buildBroadcastTxUI(); buildBroadcastTxUI();
// logout
const logout_btn = document.getElementById('logout_btn');
logout_btn.addEventListener('click', localbitcoinplusplus.actions.reset_flo_keys);
if ( if (
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes( localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
MY_LOCAL_FLO_PUBLIC_KEY MY_LOCAL_FLO_PUBLIC_KEY