From a6913153404e6fed6003b056f0238a80c2dc6105 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 25 Nov 2017 17:10:21 +0200 Subject: [PATCH] Fix logout and improve login-related management replies. Fixes #6 --- src/commands.js | 7 +++---- src/matrix-user.js | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/commands.js b/src/commands.js index 62aa92b7..4f47efb4 100644 --- a/src/commands.js +++ b/src/commands.js @@ -95,7 +95,7 @@ commands.enterPassword = async (sender, args, reply) => { const hash = makePasswordHash(sender.commandStatus.salt, args[0]) try { await sender.checkPassword(hash) - reply(`Logged in successfully as @${sender.telegramPuppet.getDisplayName()}.`) + reply(`Logged in successfully as ${sender.telegramPuppet.getDisplayName()}.`) sender.commandStatus = undefined } catch (err) { reply(`**Login failed:** ${err}`) @@ -118,7 +118,7 @@ commands.enterCode = async (sender, args, reply) => { try { const data = await sender.signInToTelegram(args[0]) if (data.status === "ok") { - reply(`Logged in successfully as @${sender.telegramPuppet.getDisplayName()}.`) + reply(`Logged in successfully as ${sender.telegramPuppet.getDisplayName()}.`) sender.commandStatus = undefined } else if (data.status === "need-password") { reply(`You have two-factor authentication enabled. Password hint: ${data.hint} @@ -132,7 +132,6 @@ Enter your password using \`$cmdprefix \``) reply(`Unexpected sign in response, status=${data.status}`) } } catch (err) { - // TODO login fails somewhere with TypeError: Cannot read property 'status' of undefined reply(`**Login failed:** ${err}`) if (err instanceof Error) { reply(["```", err.stack, "```"].join("")) @@ -153,7 +152,7 @@ commands.login = async (sender, args, reply) => { try { /*const data = */ await sender.sendTelegramCode(args[0]) - reply(`Login code sent to ${args[0]}.\nEnter the code using "$cmdprefix "`) + reply(`Login code sent to ${args[0]}.\nEnter the code using \`$cmdprefix \``) sender.commandStatus = { action: "Phone code authentication", next: commands.enterCode, diff --git a/src/matrix-user.js b/src/matrix-user.js index 622cc484..07d2dce6 100644 --- a/src/matrix-user.js +++ b/src/matrix-user.js @@ -30,6 +30,7 @@ class MatrixUser { this.phoneNumber = undefined this.phoneCodeHash = undefined this.commandStatus = undefined + this.puppetData = undefined this.contacts = [] this._telegramPuppet = undefined } @@ -204,10 +205,8 @@ class MatrixUser { } async logOutFromTelegram() { - const ok = await this.telegramPuppet.logOut() - if (!ok) { - return false - } + this.telegramPuppet.logOut() + // TODO kick user from all portals this._telegramPuppet = undefined this.puppetData = undefined await this.save()