From a6ee05ef93505f1323e47fb1445a91c7d0cd7bd9 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 21 Jul 2017 10:54:41 -0400 Subject: [PATCH] added option to disable auto totp copying --- src/_locales/en/messages.json | 8 ++ src/background.js | 15 ++- src/popup/app/current/currentController.js | 12 ++- .../settings/settingsFeaturesController.js | 97 +++++++++++++------ .../app/settings/views/settingsFeatures.html | 11 +++ src/services/constantsService.js | 1 + src/services/totpService.js | 19 +++- 7 files changed, 125 insertions(+), 38 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 905dba65..3e821ed2 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -830,5 +830,13 @@ "refreshComplete": { "message": "Refresh complete", "description": "Refresh complete" + }, + "disableAutoTotpCopy": { + "message": "Disable Automatic TOTP Copy", + "description": "Disable Automatic TOTP Copy" + }, + "disableAutoTotpCopyDesc": { + "message": "If your login has an authenticator key attached to it, the TOTP verification code is automatically copied to your clipboard whenever you auto-fill the login.", + "description": "If your login has an authenticator key attached to it, the TOTP verification code is automatically copied to your clipboard whenever you auto-fill the login." } } diff --git a/src/background.js b/src/background.js index 1694c644..7b3f4c33 100644 --- a/src/background.js +++ b/src/background.js @@ -17,7 +17,7 @@ var bg_syncService = new SyncService(bg_loginService, bg_folderService, bg_userS bg_cryptoService, logout); var bg_autofillService = new AutofillService(); var bg_passwordGenerationService = new PasswordGenerationService(); -var bg_totpService = new TotpService(); +var bg_totpService = new TotpService(bg_constantsService); if (chrome.commands) { chrome.commands.onCommand.addListener(function (command) { @@ -609,8 +609,17 @@ function autofillPage() { }, { frameId: pageDetailsToAutoFill[i].frameId }); if (!bg_utilsService.isFirefox() && loginToAutoFill.totp && bg_tokenService.getPremium()) { - bg_totpService.getCode(loginToAutoFill.totp).then(function (code) { - bg_utilsService.copyToClipboard(code); + var totpKey = loginToAutoFill.totp; + bg_totpService.isAutoCopyEnabled().then(function (enabled) { + if (enabled) { + return bg_totpService.getCode(totpKey); + } + + return null; + }).then(function (code) { + if (code) { + bg_utilsService.copyToClipboard(code); + } }); } } diff --git a/src/popup/app/current/currentController.js b/src/popup/app/current/currentController.js index edf1debc..af5bf182 100644 --- a/src/popup/app/current/currentController.js +++ b/src/popup/app/current/currentController.js @@ -86,8 +86,16 @@ angular }, { frameId: pageDetails[i].frameId }, $window.close); if (login.totp && tokenService.getPremium()) { - totpService.getCode(login.totp).then(function (code) { - utilsService.copyToClipboard(code); + totpService.isAutoCopyEnabled().then(function (enabled) { + if (enabled) { + return totpService.getCode(login.totp); + } + + return null; + }).then(function (code) { + if (code) { + utilsService.copyToClipboard(code); + } }); } } diff --git a/src/popup/app/settings/settingsFeaturesController.js b/src/popup/app/settings/settingsFeaturesController.js index 6af55e58..44e02694 100644 --- a/src/popup/app/settings/settingsFeaturesController.js +++ b/src/popup/app/settings/settingsFeaturesController.js @@ -1,45 +1,52 @@ angular .module('bit.settings') - .controller('settingsFeaturesController', function ($scope, i18nService, $analytics, constantsService, utilsService) { + .controller('settingsFeaturesController', function ($scope, i18nService, $analytics, constantsService, utilsService, + totpService, $timeout) { $scope.i18n = i18nService; $scope.disableGa = false; $scope.disableAddLoginNotification = false; $scope.disableContextMenuItem = false; chrome.storage.local.get(constantsService.disableGaKey, function (obj) { - // Default for Firefox is disabled. - if ((utilsService.isFirefox() && obj[constantsService.disableGaKey] === undefined) || - obj[constantsService.disableGaKey]) { - $scope.disableGa = true; - } - else { - $scope.disableGa = false; - } - - $scope.$apply(); + $timeout(function () { + // Default for Firefox is disabled. + if ((utilsService.isFirefox() && obj[constantsService.disableGaKey] === undefined) || + obj[constantsService.disableGaKey]) { + $scope.disableGa = true; + } + else { + $scope.disableGa = false; + } + }); }); chrome.storage.local.get(constantsService.disableAddLoginNotificationKey, function (obj) { - if (obj && obj[constantsService.disableAddLoginNotificationKey]) { - $scope.disableAddLoginNotification = true; - } - else { - $scope.disableAddLoginNotification = false; - } - - $scope.$apply(); + $timeout(function () { + if (obj && obj[constantsService.disableAddLoginNotificationKey]) { + $scope.disableAddLoginNotification = true; + } + else { + $scope.disableAddLoginNotification = false; + } + }); }); chrome.storage.local.get(constantsService.disableContextMenuItemKey, function (obj) { - if (obj && obj[constantsService.disableContextMenuItemKey]) { - $scope.disableContextMenuItem = true; - } - else { - $scope.disableContextMenuItem = false; - } + $timeout(function () { + if (obj && obj[constantsService.disableContextMenuItemKey]) { + $scope.disableContextMenuItem = true; + } + else { + $scope.disableContextMenuItem = false; + } + }); + }); - $scope.$apply(); + totpService.isAutoCopyEnabled().then(function (enabled) { + $timeout(function () { + $scope.disableAutoTotpCopy = !enabled; + }); }); $scope.updateGa = function () { @@ -57,8 +64,9 @@ } chrome.storage.local.set(obj, function () { - $scope.disableGa = obj[constantsService.disableGaKey]; - $scope.$apply(); + $timeout(function () { + $scope.disableGa = obj[constantsService.disableGaKey]; + }); if (!obj[constantsService.disableGaKey]) { $analytics.eventTrack('Enabled Analytics'); } @@ -79,8 +87,9 @@ } chrome.storage.local.set(obj, function () { - $scope.disableAddLoginNotification = obj[constantsService.disableAddLoginNotificationKey]; - $scope.$apply(); + $timeout(function () { + $scope.disableAddLoginNotification = obj[constantsService.disableAddLoginNotificationKey]; + }); if (!obj[constantsService.disableAddLoginNotificationKey]) { $analytics.eventTrack('Enabled Add Login Notification'); } @@ -101,8 +110,9 @@ } chrome.storage.local.set(obj, function () { - $scope.disableContextMenuItem = obj[constantsService.disableContextMenuItemKey]; - $scope.$apply(); + $timeout(function () { + $scope.disableContextMenuItem = obj[constantsService.disableContextMenuItemKey]; + }); if (!obj[constantsService.disableContextMenuItemKey]) { $analytics.eventTrack('Enabled Context Menu Item'); } @@ -112,4 +122,27 @@ }); }); }; + + $scope.updateAutoTotpCopy = function () { + chrome.storage.local.get(constantsService.disableAutoTotpCopyKey, function (obj) { + if (obj[constantsService.disableAutoTotpCopyKey]) { + // enable + obj[constantsService.disableAutoTotpCopyKey] = false; + } + else { + // disable + $analytics.eventTrack('Disabled Auto Copy TOTP'); + obj[constantsService.disableAutoTotpCopyKey] = true; + } + + chrome.storage.local.set(obj, function () { + $timeout(function () { + $scope.disableAutoTotpCopy = obj[constantsService.disableAutoTotpCopyKey]; + }); + if (!obj[constantsService.disableAutoTotpCopyKey]) { + $analytics.eventTrack('Enabled Auto Copy TOTP'); + } + }); + }); + }; }); diff --git a/src/popup/app/settings/views/settingsFeatures.html b/src/popup/app/settings/views/settingsFeatures.html index 6749bc6d..e4fa25f5 100644 --- a/src/popup/app/settings/views/settingsFeatures.html +++ b/src/popup/app/settings/views/settingsFeatures.html @@ -6,6 +6,17 @@
+
+
+
+ + +
+
+ +
diff --git a/src/services/constantsService.js b/src/services/constantsService.js index f80a4c95..ffc5cc77 100644 --- a/src/services/constantsService.js +++ b/src/services/constantsService.js @@ -3,6 +3,7 @@ function ConstantsService() { disableGaKey: 'disableGa', disableAddLoginNotificationKey: 'disableAddLoginNotification', disableContextMenuItemKey: 'disableContextMenuItem', + disableAutoTotpCopyKey: 'disableAutoTotpCopy', lockOptionKey: 'lockOption', lastActiveKey: 'lastActive', encType: { diff --git a/src/services/totpService.js b/src/services/totpService.js index 4cfc5500..389e62f4 100644 --- a/src/services/totpService.js +++ b/src/services/totpService.js @@ -1,4 +1,5 @@ -function TotpService() { +function TotpService(constantsService) { + this.constantsService = constantsService; initTotpService(); } @@ -105,4 +106,20 @@ function initTotpService() { return otp; }); }; + + TotpService.prototype.isAutoCopyEnabled = function () { + var deferred = Q.defer(); + var self = this; + + chrome.storage.local.get(self.constantsService.disableAutoTotpCopyKey, function (obj) { + if (obj && !!obj[self.constantsService.disableAutoTotpCopyKey]) { + deferred.resolve(false); + } + else { + deferred.resolve(true); + } + }); + + return deferred.promise; + }; }