From 458894a8bf6cf82a65f41b5b533198931907d718 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 26 Jul 2016 05:54:11 +0200 Subject: [PATCH] Improvements in account handling; detection for a mismatch between selected account and used account authorization. --- .../telegram_backup/CommandLineController.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java index e4b76f7..5f63df3 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java @@ -118,10 +118,16 @@ public class CommandLineController { logger.info("Creating UserManager"); user = new UserManager(client); - if (!CommandLineOptions.cmd_login && user.getUser()==null) { + if (!CommandLineOptions.cmd_login && !user.isLoggedIn()) { System.out.println("Your authorization data is invalid or missing. You will have to login with Telegram again."); CommandLineOptions.cmd_login = true; } + if (account!=null && user.isLoggedIn()) { + if (!account.equals("+" + user.getUser().getPhone())) { + logger.error("Account: {}, user.getUser().getPhone(): +{}", account, user.getUser().getPhone()); + throw new RuntimeException("Account / User mismatch"); + } + } logger.debug("CommandLineOptions.val_export: {}", CommandLineOptions.val_export); if (CommandLineOptions.val_export != null) { @@ -142,7 +148,11 @@ public class CommandLineController { System.exit(0); } - System.out.println("You are logged in as " + user.getUserString()); + if (user.isLoggedIn()) { + System.out.println("You are logged in as " + user.getUserString()); + } else { + System.out.println("You are not logged in."); + } logger.info("Initializing Download Manager"); DownloadManager d = new DownloadManager(user, client, new CommandLineDownloadProgress()); @@ -178,13 +188,13 @@ public class CommandLineController { user.verifyCode(code); if (user.isPasswordNeeded()) { - System.out.println("We also need your account password."); + System.out.println("We also need your account password. Please enter it now. It should not be printed, so it's okay if you see nothing while typing it."); String pw = getPassword(); user.verifyPassword(pw); } storage.setPrefix("+" + user.getUser().getPhone()); - System.out.println("Please run this tool with '--account +" + user.getUser().getPhone() + " to use this account."); + System.out.println("Everything seems fine. Please run this tool again with '--account +" + user.getUser().getPhone() + " to use this account."); } private String getLine() {