diff options
author | Marvin Borner | 2019-01-27 21:07:55 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-27 21:07:55 +0100 |
commit | 6ad56b575741229ead2226e4b64b905cc950167d (patch) | |
tree | 7412e44850d934998e22484d79cbe5b79fe453ea | |
parent | b07aaae8d635548f859fcc0573be00534a8759dc (diff) |
Added logout & delete buttons
-rw-r--r-- | public/scripts/chat.js | 78 | ||||
-rw-r--r-- | public/styles/pin.sass | 1 | ||||
-rw-r--r-- | public/styles/style.sass | 2 | ||||
-rw-r--r-- | views/index.pug | 8 |
4 files changed, 48 insertions, 41 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index 53b6e1d..088cb72 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -32,6 +32,43 @@ generator.initWithWordList(wordList); })(); /** + * Evaluates whether a key generation is needed and initializes regarding actions + * @returns {Promise<void>} + */ +async function evaluateKeyGeneration() { + if (localStorage.getItem('database') === 'success' && await encryption.check()) { + pinInput.init(async (pin, tryCount) => { + try { + if (await encryption.getId(await encryption.getPublic()) !== peerId) throw "Not verified!"; + passphrase = pin; + await encryption.decryptPrivate(await encryption.getPrivate(), pin); + chat() + } catch (e) { // decrypting failed + if (tryCount === 3) { + encryption.reset(); + console.error('Too many tries!'); + pinInput.failure('This account got removed, the site will reload.'); + setTimeout(() => location.reload(), 1500) + } else if (e === 'Not verified!') { + console.error(e); + pinInput.failure(e); + } else { + console.error('Passphrase is wrong!'); + pinInput.failure('Passphrase is wrong!'); + } + } + }); + } else { + pinInput.init(pin => { + console.log('[LOG] No existing keys found! Generating...'); + pinInput.generate(); + passphrase = pin; + (async () => await encryption.generate(peerId, passphrase).then(() => chat()))() + }); + } +} + +/** * Initializes chat functions */ function chat() { @@ -119,45 +156,10 @@ function chat() { */ $(document).ready(() => { $('#add_peer_id').on('click', async () => await connect($('#peer_id').val())); - $('#send_message').on('click', async () => await sendMessage($('#message').val())); + $('#send_message').on('click', async () => await sendMessage($('#message').val()) & $('#message').val('')); + $('#logout').on('click', () => location.reload()); + $('#delete').on('click', () => encryption.reset() & location.reload()); $('[toggle-contact-modal]').on('click', () => $('#add_contact_modal').toggleClass('is-active')) }); } - -/** - * Evaluates whether a key generation is needed and initializes regarding actions - * @returns {Promise<void>} - */ -async function evaluateKeyGeneration() { - if (localStorage.getItem('database') === 'success' && await encryption.check()) { - pinInput.init(async (pin, tryCount) => { - try { - if (await encryption.getId(await encryption.getPublic()) !== peerId) throw "Not verified!"; - passphrase = pin; - await encryption.decryptPrivate(await encryption.getPrivate(), pin); - chat() - } catch (e) { // decrypting failed - if (tryCount === 3) { - encryption.reset(); - console.error('Too many tries!'); - pinInput.failure('This account got removed, the site will reload.'); - setTimeout(() => location.reload(), 1500) - } else if (e === 'Not verified!') { - console.error(e); - pinInput.failure(e); - } else { - console.error('Passphrase is wrong!'); - pinInput.failure('Passphrase is wrong!'); - } - } - }); - } else { - pinInput.init(pin => { - console.log('[LOG] No existing keys found! Generating...'); - pinInput.generate(); - passphrase = pin; - (async () => await encryption.generate(peerId, passphrase).then(() => chat()))() - }); - } -} diff --git a/public/styles/pin.sass b/public/styles/pin.sass index 3aea4fc..6578f08 100644 --- a/public/styles/pin.sass +++ b/public/styles/pin.sass @@ -32,6 +32,7 @@ margin: 0 .pin-wrapper > .column input:focus + background-color: #394046 border-color: inherit -webkit-box-shadow: none box-shadow: none diff --git a/public/styles/style.sass b/public/styles/style.sass index 4d38d4b..d61fdf2 100644 --- a/public/styles/style.sass +++ b/public/styles/style.sass @@ -10,7 +10,7 @@ html, body .main align-items: flex-start -.add-peer-button +.action-button height: 50px width: 50px margin: 20px diff --git a/views/index.pug b/views/index.pug index 2c6528a..0375186 100644 --- a/views/index.pug +++ b/views/index.pug @@ -2,10 +2,14 @@ extends layout block content .chat#chat - button.button.add-peer-button.is-big.is-outlined.is-info(toggle-contact-modal) + button.button.action-button.is-big.is-outlined.is-info(toggle-contact-modal) i.fas.fa-plus + button.button.action-button.is-big.is-outlined.is-warning#logout + i.fas.fa-sign-out-alt + button.button.action-button.is-big.is-outlined.is-danger#delete + i.fas.fa-trash - .columns.level.main + .columns.main.level .section.column.level-right #messages .message-field |