From 31b9c6972856514b7023e7d46414404fe0fed633 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 17 Nov 2019 01:46:55 +0000 Subject: [PATCH 1/4] SecureSign hash error handler --- src/functions/checkSS.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index ee4bd6d..751b95c 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -4,22 +4,26 @@ import { Client } from '..'; export default function checkSS(client: Client) { setInterval(async () => { - const accounts = await client.db.Account.find(); - const hashes = accounts.filter((h) => h.hash); - for (const { hash, userID } of hashes) { - try { - await axios({ - method: 'get', - url: 'https://api.securesign.org/account/details', - headers: { Authorization: hash }, - }); - } catch (error) { - const { status } = error.response; - if (status === 400 || status === 401 || status === 403 || status === 404) { - client.db.Account.updateOne({ hash }, { $set: { hash: null } }); - client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); + try { + const accounts = await client.db.Account.find(); + const hashes = accounts.filter((h) => h.hash); + for (const { hash, userID } of hashes) { + try { + await axios({ + method: 'get', + url: 'https://api.securesign.org/account/details', + headers: { Authorization: hash }, + }); + } catch (error) { + const { status } = error.response; + if (status === 400 || status === 401 || status === 403 || status === 404) { + client.db.Account.updateOne({ hash }, { $set: { hash: null } }); + client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); + } } } + } catch (error) { + client.util.handleError(error); } }, 60000); } From 8cf1157442a77a310345de58cfe4c0b46a2ec7cf Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 17 Nov 2019 01:53:38 +0000 Subject: [PATCH 2/4] Fix? --- src/functions/checkSS.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 751b95c..45868b6 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -17,7 +17,7 @@ export default function checkSS(client: Client) { } catch (error) { const { status } = error.response; if (status === 400 || status === 401 || status === 403 || status === 404) { - client.db.Account.updateOne({ hash }, { $set: { hash: null } }); + await client.db.Account.updateOne({ hash }, { $set: { hash: null } }); client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); } } From 48468754c5e53116e083a7190d8ff1d5b42969a5 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 17 Nov 2019 02:57:33 +0000 Subject: [PATCH 3/4] Added activatekey subcommand --- src/commands/securesign.ts | 3 +- src/commands/securesign_activatekey.ts | 45 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/commands/securesign_activatekey.ts diff --git a/src/commands/securesign.ts b/src/commands/securesign.ts index f143b95..275b6fe 100644 --- a/src/commands/securesign.ts +++ b/src/commands/securesign.ts @@ -4,6 +4,7 @@ import { Client } from '..'; import Build from './securesign_build'; import Init from './securesign_init'; import Account from './securesign_account'; +import ActivateKey from './securesign_activatekey'; export default class SecureSign extends Command { constructor(client: Client) { @@ -12,7 +13,7 @@ export default class SecureSign extends Command { this.description = 'Runs SecureSign CLI commands'; this.usage = `Run ${this.client.config.prefix}${this.name} [subcommand] for usage information`; this.aliases = ['ss']; - this.subcmds = [Build, Init, Account]; + this.subcmds = [Build, Init, Account, ActivateKey]; this.enabled = true; } diff --git a/src/commands/securesign_activatekey.ts b/src/commands/securesign_activatekey.ts new file mode 100644 index 0000000..995e785 --- /dev/null +++ b/src/commands/securesign_activatekey.ts @@ -0,0 +1,45 @@ +import { Message } from 'eris'; +import axios from 'axios'; +import { Client } from '..'; +import { Command, RichEmbed } from '../class'; + +export default class SecureSign_ActivateKey extends Command { + constructor(client: Client) { + super(client); + this.name = 'activatekey'; + this.description = 'Claims an Activation Key'; + this.usage = `${this.client.config.prefix}securesign activatekey [key]`; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, ['securesign', this.name]); + const account = await this.client.db.Account.findOne({ userID: message.author.id }); + if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); + if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`); + const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Activating key...***`); + try { + await axios({ + method: 'POST', + url: 'https://api.securesign.org/account/keys/activation', + headers: { Authorization: account.hash, 'Content-Type': 'application/json' }, + data: JSON.stringify({ key: args[0] }), + }); + } catch (error) { + const { code } = error.response.data; + if (code === 1001) { + await this.client.db.Account.updateOne({ hash: account.hash }, { $set: { hash: null } }); + this.client.getDMChannel(account.userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); + return msg.edit(`${this.client.stores.emojis.error} ***Authentication failed***`); + } + if (code === 1002) return msg.edit(`${this.client.stores.emojis.error} ***Invalid Activation Key***`); + if (code === 1003) return msg.edit(`${this.client.stores.emojis.error} ***${error.response.data.message}***`); + throw error; + } + return msg.edit(`${this.client.stores.emojis.success} ***Activation Key Accepted***`); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} From 1a0162734d16dcfabc02517e9511795aab808415 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 17 Nov 2019 02:57:59 +0000 Subject: [PATCH 4/4] Got rid of embed import --- src/commands/securesign_activatekey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/securesign_activatekey.ts b/src/commands/securesign_activatekey.ts index 995e785..24c78e1 100644 --- a/src/commands/securesign_activatekey.ts +++ b/src/commands/securesign_activatekey.ts @@ -1,7 +1,7 @@ import { Message } from 'eris'; import axios from 'axios'; import { Client } from '..'; -import { Command, RichEmbed } from '../class'; +import { Command } from '../class'; export default class SecureSign_ActivateKey extends Command { constructor(client: Client) {