1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-02 08:30:14 +01:00

added option to disable auto totp copying

This commit is contained in:
Kyle Spearrin 2017-07-21 10:54:41 -04:00
parent 592b14149f
commit a6ee05ef93
7 changed files with 125 additions and 38 deletions

View File

@ -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."
}
}

View File

@ -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) {
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);
}
});
}
}

View File

@ -86,8 +86,16 @@ angular
}, { frameId: pageDetails[i].frameId }, $window.close);
if (login.totp && tokenService.getPremium()) {
totpService.getCode(login.totp).then(function (code) {
totpService.isAutoCopyEnabled().then(function (enabled) {
if (enabled) {
return totpService.getCode(login.totp);
}
return null;
}).then(function (code) {
if (code) {
utilsService.copyToClipboard(code);
}
});
}
}

View File

@ -1,13 +1,15 @@
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) {
$timeout(function () {
// Default for Firefox is disabled.
if ((utilsService.isFirefox() && obj[constantsService.disableGaKey] === undefined) ||
obj[constantsService.disableGaKey]) {
@ -16,30 +18,35 @@
else {
$scope.disableGa = false;
}
$scope.$apply();
});
});
chrome.storage.local.get(constantsService.disableAddLoginNotificationKey, function (obj) {
$timeout(function () {
if (obj && obj[constantsService.disableAddLoginNotificationKey]) {
$scope.disableAddLoginNotification = true;
}
else {
$scope.disableAddLoginNotification = false;
}
$scope.$apply();
});
});
chrome.storage.local.get(constantsService.disableContextMenuItemKey, function (obj) {
$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 () {
$timeout(function () {
$scope.disableGa = obj[constantsService.disableGaKey];
$scope.$apply();
});
if (!obj[constantsService.disableGaKey]) {
$analytics.eventTrack('Enabled Analytics');
}
@ -79,8 +87,9 @@
}
chrome.storage.local.set(obj, function () {
$timeout(function () {
$scope.disableAddLoginNotification = obj[constantsService.disableAddLoginNotificationKey];
$scope.$apply();
});
if (!obj[constantsService.disableAddLoginNotificationKey]) {
$analytics.eventTrack('Enabled Add Login Notification');
}
@ -101,8 +110,9 @@
}
chrome.storage.local.set(obj, function () {
$timeout(function () {
$scope.disableContextMenuItem = obj[constantsService.disableContextMenuItemKey];
$scope.$apply();
});
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');
}
});
});
};
});

View File

@ -6,6 +6,17 @@
</div>
<div class="content">
<div class="list">
<div class="list-section">
<div class="list-section-items">
<div class="list-section-item list-section-item-checkbox">
<label for="totp-copy">{{i18n.disableAutoTotpCopy}}</label>
<input id="totp-copy" type="checkbox" ng-model="disableAutoTotpCopy" ng-change="updateAutoTotpCopy()">
</div>
</div>
<div class="list-section-footer">
{{i18n.disableAutoTotpCopyDesc}}
</div>
</div>
<div class="list-section">
<div class="list-section-items">
<div class="list-section-item list-section-item-checkbox">

View File

@ -3,6 +3,7 @@ function ConstantsService() {
disableGaKey: 'disableGa',
disableAddLoginNotificationKey: 'disableAddLoginNotification',
disableContextMenuItemKey: 'disableContextMenuItem',
disableAutoTotpCopyKey: 'disableAutoTotpCopy',
lockOptionKey: 'lockOption',
lastActiveKey: 'lastActive',
encType: {

View File

@ -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;
};
}