From e87f9e268ad311bba66c8d6c966cf49a1c8b8c46 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 17 Oct 2017 15:22:16 -0400 Subject: [PATCH] autofill ui for other types. autofill fixes --- src/_locales/en/messages.json | 7 ++- src/background.js | 2 +- .../app/components/cipherItemsComponent.js | 27 ++++++++++++ .../app/components/views/actionButtons.html | 20 ++++++--- .../app/components/views/cipherItems.html | 11 +++++ src/popup/app/current/currentController.js | 31 +++++++++---- src/popup/app/current/views/current.html | 43 ++++++++++--------- src/popup/app/vault/views/vault.html | 2 +- .../app/vault/views/vaultViewFolder.html | 2 +- src/popup/index.html | 1 + src/popup/less/components.less | 10 ++--- src/services/autofillService.js | 24 ++++++----- src/services/cipherService.js | 5 ++- 13 files changed, 130 insertions(+), 55 deletions(-) create mode 100644 src/popup/app/components/cipherItemsComponent.js create mode 100644 src/popup/app/components/views/cipherItems.html diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index fd363c4bbf..117c7a90e3 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -242,8 +242,8 @@ "edit": { "message": "Edit" }, - "noLoginsInList": { - "message": "There are no logins to list." + "noItemsInList": { + "message": "There are no items to list." }, "loginInformation": { "message": "Login Information" @@ -931,6 +931,9 @@ "typeLogin": { "message": "Login" }, + "typeLogins": { + "message": "Logins" + }, "typeSecureNote": { "message": "Secure Note" }, diff --git a/src/background.js b/src/background.js index 63c22dd4b9..e1a2d46e9c 100644 --- a/src/background.js +++ b/src/background.js @@ -736,7 +736,7 @@ var bg_isBackground = true, function autofillPage() { bg_autofillService.doAutoFill({ - login: loginToAutoFill, + cipher: loginToAutoFill, pageDetails: pageDetailsToAutoFill, fromBackground: true }); diff --git a/src/popup/app/components/cipherItemsComponent.js b/src/popup/app/components/cipherItemsComponent.js new file mode 100644 index 0000000000..5138aea509 --- /dev/null +++ b/src/popup/app/components/cipherItemsComponent.js @@ -0,0 +1,27 @@ +angular + .module('bit.components') + + .component('cipherItems', { + bindings: { + ciphers: '<', + selectionTitle: '<', + onView: '&', + onSelected: '&' + }, + templateUrl: 'app/components/views/cipherItems.html', + controller: function (i18nService) { + var ctrl = this; + + ctrl.$onInit = function () { + ctrl.i18n = i18nService; + + ctrl.view = function (cipher) { + ctrl.onView()(cipher); + }; + + ctrl.select = function (cipher) { + ctrl.onSelected()(cipher); + }; + }; + } + }); diff --git a/src/popup/app/components/views/actionButtons.html b/src/popup/app/components/views/actionButtons.html index 1fc0f2b8ad..3793107eac 100644 --- a/src/popup/app/components/views/actionButtons.html +++ b/src/popup/app/components/views/actionButtons.html @@ -1,7 +1,7 @@ 
+ ng-if="!$ctrl.showView" ng-class="{disabled: !$ctrl.cipher.login.uri}"> + data-clipboard-text="{{$ctrl.cipher.login.username}}" ng-class="{disabled: !$ctrl.cipher.login.username}"> + data-clipboard-text="{{$ctrl.cipher.login.password}}" ng-class="{disabled: !$ctrl.cipher.login.password}">
+ + + + data-clipboard-text="{{$ctrl.cipher.card.number}}" ng-class="{disabled: !$ctrl.cipher.card.number}"> + data-clipboard-text="{{$ctrl.cipher.card.code}}" ng-class="{disabled: !$ctrl.cipher.card.code}">
+
+ + + +
diff --git a/src/popup/app/components/views/cipherItems.html b/src/popup/app/components/views/cipherItems.html new file mode 100644 index 0000000000..88385d2412 --- /dev/null +++ b/src/popup/app/components/views/cipherItems.html @@ -0,0 +1,11 @@ + + + + + {{cipher.name}} + + + + {{cipher.subTitle}} + diff --git a/src/popup/app/current/currentController.js b/src/popup/app/current/currentController.js index 222fa9c5a8..ba305ede15 100644 --- a/src/popup/app/current/currentController.js +++ b/src/popup/app/current/currentController.js @@ -2,7 +2,7 @@ angular .module('bit.current') .controller('currentController', function ($scope, cipherService, utilsService, toastr, $window, $state, $timeout, - autofillService, $analytics, i18nService, totpService, tokenService) { + autofillService, $analytics, i18nService, totpService, tokenService, constantsService, $filter) { $scope.i18n = i18nService; var pageDetails = [], @@ -10,7 +10,8 @@ angular domain = null, canAutofill = false; - $scope.ciphers = []; + $scope.loginCiphers = []; + $scope.otherCiphers = []; $scope.loaded = false; $scope.searchText = null; $('#search').focus(); @@ -44,10 +45,24 @@ angular canAutofill = true; }); - cipherService.getAllDecryptedForDomain(domain).then(function (ciphers) { + var otherTypes = [constantsService.cipherType.card, constantsService.cipherType.identity]; + cipherService.getAllDecryptedForDomain(domain, otherTypes).then(function (ciphers) { + var loginCiphers = [], + otherCiphers = []; + + for (var i = 0; i < ciphers.length; i++) { + if (ciphers[i].type === constantsService.cipherType.login) { + loginCiphers.push(ciphers[i]); + } + else { + otherCiphers.push(ciphers[i]); + } + } + $timeout(function () { + $scope.loginCiphers = $filter('orderBy')(loginCiphers, [sortUriMatch, sortLastUsed, 'name', 'subTitle']); + $scope.otherCiphers = $filter('orderBy')(otherCiphers, [sortLastUsed, 'name', 'subTitle']); $scope.loaded = true; - $scope.ciphers = ciphers; }); }); }); @@ -94,14 +109,14 @@ angular }); }; - $scope.sortUriMatch = function (cipher) { + function sortUriMatch(cipher) { // exact matches should sort earlier. return url && url.startsWith(cipher.uri) ? 0 : 1; - }; + } - $scope.sortLastUsed = function (cipher) { + function sortLastUsed(cipher) { return cipher.localData && cipher.localData.lastUsedDate ? -1 * cipher.localData.lastUsedDate : 0; - }; + } $scope.searchVault = function () { $state.go('tabs.vault', { diff --git a/src/popup/app/current/views/current.html b/src/popup/app/current/views/current.html index 303f64799c..ce0f687fe7 100644 --- a/src/popup/app/current/views/current.html +++ b/src/popup/app/current/views/current.html @@ -14,29 +14,30 @@
-
-
-
- - - - - {{cipher.name}} - - - {{cipher.subTitle}} - +
+
+
+ {{i18n.typeLogins}} +
+
+
+

{{i18n.autoFillInfo}}

+ +
+ +
+
+
+
+ {{i18n.other}} +
+
+
{{i18n.noItemsInList}}
+
-
-
-

- {{i18n.autoFillInfo}} - -

diff --git a/src/popup/app/vault/views/vault.html b/src/popup/app/vault/views/vault.html index 350563b918..cd7764afd6 100644 --- a/src/popup/app/vault/views/vault.html +++ b/src/popup/app/vault/views/vault.html @@ -75,7 +75,7 @@

- {{i18n.noLoginsInList}} + {{i18n.noItemsInList}}

diff --git a/src/popup/app/vault/views/vaultViewFolder.html b/src/popup/app/vault/views/vaultViewFolder.html index 108e8f9158..451e0facd5 100644 --- a/src/popup/app/vault/views/vaultViewFolder.html +++ b/src/popup/app/vault/views/vaultViewFolder.html @@ -36,7 +36,7 @@

- {{i18n.noLoginsInList}} + {{i18n.noItemsInList}}

diff --git a/src/popup/index.html b/src/popup/index.html index 9d4337520a..4875c1e234 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -63,6 +63,7 @@ + diff --git a/src/popup/less/components.less b/src/popup/less/components.less index 15ea30b9e6..9ea5a1cb33 100644 --- a/src/popup/less/components.less +++ b/src/popup/less/components.less @@ -510,12 +510,12 @@ } } } +} - &.list-no-selection { - .list-grouped-item:not(.list-allow-selection), .list-section-item:not(.list-allow-selection) { - &:hover { - background-color: white; - } +.list-no-selection { + .list-grouped-item:not(.list-allow-selection), .list-section-item:not(.list-allow-selection) { + &:hover { + background-color: white; } } } diff --git a/src/services/autofillService.js b/src/services/autofillService.js index 1ec703518f..6c8aa8499d 100644 --- a/src/services/autofillService.js +++ b/src/services/autofillService.js @@ -201,7 +201,7 @@ function initAutofill() { return; } - if (!tab || !options.login || !options.pageDetails || !options.pageDetails.length) { + if (!tab || !options.cipher || !options.pageDetails || !options.pageDetails.length) { deferred.reject(); return; } @@ -213,20 +213,24 @@ function initAutofill() { continue; } - var fillScript = self.generateFillScript(options.pageDetails[i].details, { - username: options.login.username, - password: options.login.password, - fields: options.login.fields, + var fillOptions = { + fields: options.cipher.fields, skipUsernameOnlyFill: options.skipUsernameOnlyFill || false - }); + }; + if (options.cipher.login) { + fillOptions.username = options.cipher.login.username; + fillOptions.password = options.cipher.login.password; + } + + var fillScript = self.generateFillScript(options.pageDetails[i].details, fillOptions); if (!fillScript || !fillScript.script || !fillScript.script.length) { continue; } didAutofill = true; if (!options.skipLastUsed) { - self.cipherService.updateLastUsedDate(options.login.id); + self.cipherService.updateLastUsedDate(options.cipher.id); } chrome.tabs.sendMessage(tab.id, { @@ -235,14 +239,14 @@ function initAutofill() { }, { frameId: options.pageDetails[i].frameId }); if (totpPromise || (options.fromBackground && self.utilsService.isFirefox()) || - options.skipTotp || !options.login.totp || !self.tokenService.getPremium()) { + options.skipTotp || !options.cipher.login || !options.cipher.login.totp || !self.tokenService.getPremium()) { continue; } totpPromise = self.totpService.isAutoCopyEnabled().then(function (enabled) { if (enabled) { /* jshint ignore:start */ - return self.totpService.getCode(options.login.totp); + return self.totpService.getCode(options.cipher.login.totp); /* jshint ignore:end */ } @@ -300,7 +304,7 @@ function initAutofill() { } self.doAutoFill({ - login: cipher, + cipher: cipher, pageDetails: pageDetails, fromBackground: true, skipTotp: !fromCommand, diff --git a/src/services/cipherService.js b/src/services/cipherService.js index b6e1d5cc8f..b2c522d69e 100644 --- a/src/services/cipherService.js +++ b/src/services/cipherService.js @@ -260,7 +260,7 @@ function initCipherService() { }); }; - CipherService.prototype.getAllDecryptedForDomain = function (domain) { + CipherService.prototype.getAllDecryptedForDomain = function (domain, includeOtherTypes) { var self = this; var eqDomainsPromise = self.settingsService.getEquivalentDomains().then(function (eqDomains) { @@ -288,6 +288,9 @@ function initCipherService() { matchingDomains.indexOf(ciphers[i].login.domain) > -1) { ciphersToReturn.push(ciphers[i]); } + else if (includeOtherTypes && includeOtherTypes.indexOf(ciphers[i].type) > -1) { + ciphersToReturn.push(ciphers[i]); + } } return ciphersToReturn;