1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

fixes from refactors

This commit is contained in:
Kyle Spearrin
2017-10-18 14:56:59 -04:00
parent 4510c80395
commit 74eeb1a3c1
6 changed files with 103 additions and 91 deletions

View File

@@ -205,29 +205,29 @@ var bg_isBackground = true,
return; return;
} }
bg_cipherService.getAllDecrypted().then(function (logins) { bg_cipherService.getAllDecrypted().then(function (ciphers) {
for (var i = 0; i < logins.length; i++) { for (var i = 0; i < ciphers.length; i++) {
if (logins[i].id === id) { if (ciphers[i].id === id) {
if (info.parentMenuItemId === 'autofill') { if (info.parentMenuItemId === 'autofill') {
ga('send', { ga('send', {
hitType: 'event', hitType: 'event',
eventAction: 'Autofilled From Context Menu' eventAction: 'Autofilled From Context Menu'
}); });
startAutofillPage(logins[i]); startAutofillPage(ciphers[i]);
} }
else if (info.parentMenuItemId === 'copy-username') { else if (info.parentMenuItemId === 'copy-username') {
ga('send', { ga('send', {
hitType: 'event', hitType: 'event',
eventAction: 'Copied Username From Context Menu' eventAction: 'Copied Username From Context Menu'
}); });
bg_utilsService.copyToClipboard(logins[i].username); bg_utilsService.copyToClipboard(ciphers[i].login.username);
} }
else if (info.parentMenuItemId === 'copy-password') { else if (info.parentMenuItemId === 'copy-password') {
ga('send', { ga('send', {
hitType: 'event', hitType: 'event',
eventAction: 'Copied Password From Context Menu' eventAction: 'Copied Password From Context Menu'
}); });
bg_utilsService.copyToClipboard(logins[i].password); bg_utilsService.copyToClipboard(ciphers[i].login.password);
} }
return; return;
} }
@@ -260,16 +260,16 @@ var bg_isBackground = true,
if (bg_utilsService.isFirefox()) { if (bg_utilsService.isFirefox()) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
bg_cipherService.getAllDecryptedForDomain(domain).then(function (logins) { bg_cipherService.getAllDecryptedForDomain(domain).then(function (ciphers) {
if (!logins || logins.length !== 1) { if (!ciphers || ciphers.length !== 1) {
reject(); reject();
return; return;
} }
resolve({ resolve({
authCredentials: { authCredentials: {
username: logins[0].username, username: ciphers[0].login.username,
password: logins[0].password password: ciphers[0].login.password
} }
}); });
}, function () { }, function () {
@@ -278,16 +278,16 @@ var bg_isBackground = true,
}); });
} }
else { else {
bg_cipherService.getAllDecryptedForDomain(domain).then(function (logins) { bg_cipherService.getAllDecryptedForDomain(domain).then(function (ciphers) {
if (!logins || logins.length !== 1) { if (!ciphers || ciphers.length !== 1) {
callback(); callback();
return; return;
} }
callback({ callback({
authCredentials: { authCredentials: {
username: logins[0].username, username: ciphers[0].login.username,
password: logins[0].password password: ciphers[0].login.password
} }
}); });
}, function () { }, function () {
@@ -580,16 +580,16 @@ var bg_isBackground = true,
}); });
} }
function addLogin(login, tab) { function addLogin(loginInfo, tab) {
var loginDomain = bg_utilsService.getDomain(login.url); var loginDomain = bg_utilsService.getDomain(loginInfo.url);
if (!loginDomain) { if (!loginDomain) {
return; return;
} }
bg_cipherService.getAllDecryptedForDomain(loginDomain).then(function (logins) { bg_cipherService.getAllDecryptedForDomain(loginDomain).then(function (ciphers) {
var match = false; var match = false;
for (var i = 0; i < logins.length; i++) { for (var i = 0; i < ciphers.length; i++) {
if (logins[i].username === login.username) { if (ciphers[i].login.username === loginInfo.username) {
match = true; match = true;
break; break;
} }
@@ -600,11 +600,11 @@ var bg_isBackground = true,
removeAddLogin(tab); removeAddLogin(tab);
bg_loginsToAdd.push({ bg_loginsToAdd.push({
username: login.username, username: loginInfo.username,
password: login.password, password: loginInfo.password,
name: loginDomain, name: loginDomain,
domain: loginDomain, domain: loginDomain,
uri: login.url, uri: loginInfo.url,
tabId: tab.id, tabId: tab.id,
expires: new Date((new Date()).getTime() + 30 * 60000) // 30 minutes expires: new Date((new Date()).getTime() + 30 * 60000) // 30 minutes
}); });
@@ -633,53 +633,62 @@ var bg_isBackground = true,
function saveAddLogin(tab) { function saveAddLogin(tab) {
for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) { for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) {
if (bg_loginsToAdd[i].tabId === tab.id) { if (bg_loginsToAdd[i].tabId !== tab.id) {
var loginToAdd = bg_loginsToAdd[i]; continue;
var tabDomain = bg_utilsService.getDomain(tab.url);
if (tabDomain && tabDomain === loginToAdd.domain) {
bg_loginsToAdd.splice(i, 1);
/* jshint ignore:start */
bg_cipherService.encrypt({
id: null,
folderId: null,
favorite: false,
name: loginToAdd.name,
uri: loginToAdd.uri,
username: loginToAdd.username,
password: loginToAdd.password,
notes: null
}).then(function (loginModel) {
var login = new Login(loginModel, true);
bg_cipherService.saveWithServer(login).then(function (login) {
ga('send', {
hitType: 'event',
eventAction: 'Added Login from Notification Bar'
});
});
});
/* jshint ignore:end */
messageTab(tab.id, 'closeNotificationBar');
}
} }
var loginInfo = bg_loginsToAdd[i];
var tabDomain = bg_utilsService.getDomain(tab.url);
if (tabDomain && tabDomain !== loginInfo.domain) {
continue;
}
bg_loginsToAdd.splice(i, 1);
/* jshint ignore:start */
bg_cipherService.encrypt({
id: null,
folderId: null,
favorite: false,
name: loginInfo.name,
notes: null,
type: bg_constantsService.cipherType.login,
login: {
uri: loginInfo.uri,
username: loginInfo.username,
password: loginInfo
}
}).then(function (model) {
var cipher = new Cipher(model, true);
return bg_cipherService.saveWithServer(cipher);
}).then(function (login) {
ga('send', {
hitType: 'event',
eventAction: 'Added Login from Notification Bar'
});
});
/* jshint ignore:end */
messageTab(tab.id, 'closeNotificationBar');
} }
} }
function saveNever(tab) { function saveNever(tab) {
for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) { for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) {
if (bg_loginsToAdd[i].tabId === tab.id) { if (bg_loginsToAdd[i].tabId !== tab.id) {
var loginToAdd = bg_loginsToAdd[i]; continue;
var tabDomain = bg_utilsService.getDomain(tab.url);
if (tabDomain && tabDomain === loginToAdd.domain) {
bg_loginsToAdd.splice(i, 1);
var hostname = bg_utilsService.getHostname(tab.url);
bg_cipherService.saveNeverDomain(hostname);
messageTab(tab.id, 'closeNotificationBar');
}
} }
var loginInfo = bg_loginsToAdd[i];
var tabDomain = bg_utilsService.getDomain(tab.url);
if (tabDomain && tabDomain !== loginInfo.domain) {
continue;
}
bg_loginsToAdd.splice(i, 1);
var hostname = bg_utilsService.getHostname(tab.url);
bg_cipherService.saveNeverDomain(hostname);
messageTab(tab.id, 'closeNotificationBar');
} }
} }
@@ -711,18 +720,20 @@ var bg_isBackground = true,
} }
for (var i = 0; i < bg_loginsToAdd.length; i++) { for (var i = 0; i < bg_loginsToAdd.length; i++) {
if (bg_loginsToAdd[i].tabId === tab.id && bg_loginsToAdd[i].domain === tabDomain) { if (bg_loginsToAdd[i].tabId !== tab.id || bg_loginsToAdd[i].domain !== tabDomain) {
messageTab(tab.id, 'openNotificationBar', { continue;
type: 'add'
}, function () { });
break;
} }
messageTab(tab.id, 'openNotificationBar', {
type: 'add'
}, function () { });
break;
} }
} }
} }
function startAutofillPage(login) { function startAutofillPage(cipher) {
loginToAutoFill = login; loginToAutoFill = cipher;
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var tab = null; var tab = null;
if (tabs.length > 0) { if (tabs.length > 0) {
@@ -740,8 +751,7 @@ var bg_isBackground = true,
command: 'collectPageDetails', command: 'collectPageDetails',
tab: tab, tab: tab,
sender: 'contextMenu' sender: 'contextMenu'
}, function () { }, function () { });
});
}); });
} }

View File

@@ -10,11 +10,11 @@ angular
$scope.canAccessAttachments = $scope.isPremium; $scope.canAccessAttachments = $scope.isPremium;
$scope.hasUpdatedKey = false; $scope.hasUpdatedKey = false;
cipherService.get($stateParams.id).then(function (login) { cipherService.get($stateParams.id).then(function (cipher) {
return login.decrypt(); return cipher.decrypt();
}).then(function (model) { }).then(function (model) {
$scope.login = model; $scope.cipher = model;
$scope.canAccessAttachments = $scope.isPremium || !!$scope.login.organizationId; $scope.canAccessAttachments = $scope.isPremium || !!$scope.cipher.organizationId;
if (!$scope.canAccessAttachments) { if (!$scope.canAccessAttachments) {
SweetAlert.swal({ SweetAlert.swal({
@@ -69,9 +69,9 @@ angular
return deferred.promise; return deferred.promise;
} }
$scope.submitPromise = cipherService.saveAttachmentWithServer($scope.login, files[0]).then(function (login) { $scope.submitPromise = cipherService.saveAttachmentWithServer($scope.cipher, files[0]).then(function (cipher) {
login.decrypt().then(function (model) { cipher.decrypt().then(function (model) {
$scope.login = model; $scope.cipher = model;
}); });
$analytics.eventTrack('Added Attachment'); $analytics.eventTrack('Added Attachment');
toastr.success(i18nService.attachmentSaved); toastr.success(i18nService.attachmentSaved);
@@ -101,9 +101,9 @@ angular
}, function (confirmed) { }, function (confirmed) {
if (confirmed) { if (confirmed) {
cipherService.deleteAttachmentWithServer($stateParams.id, attachment.id).then(function () { cipherService.deleteAttachmentWithServer($stateParams.id, attachment.id).then(function () {
var index = $scope.login.attachments.indexOf(attachment); var index = $scope.cipher.attachments.indexOf(attachment);
if (index > -1) { if (index > -1) {
$scope.login.attachments.splice(index, 1); $scope.cipher.attachments.splice(index, 1);
} }
$analytics.eventTrack('Deleted Attachment'); $analytics.eventTrack('Deleted Attachment');
toastr.success(i18nService.deletedAttachment); toastr.success(i18nService.deletedAttachment);
@@ -114,7 +114,7 @@ angular
$scope.close = function () { $scope.close = function () {
$state.go('editCipher', { $state.go('editCipher', {
loginId: $stateParams.id, cipherId: $stateParams.id,
animation: 'out-slide-down', animation: 'out-slide-down',
from: $stateParams.from, from: $stateParams.from,
fromView: $stateParams.fromView fromView: $stateParams.fromView

View File

@@ -13,14 +13,16 @@
<div class="list list-no-selection"> <div class="list list-no-selection">
<div class="list-section"> <div class="list-section">
<div class="list-section-items"> <div class="list-section-items">
<div class="list-section-item" ng-if="!login.attachments.length"> <div class="list-section-item" ng-if="!cipher.attachments.length">
{{i18n.noAttachments}} {{i18n.noAttachments}}
</div> </div>
<div class="list-section-item" ng-repeat="attachment in login.attachments"> <div class="list-section-item" ng-repeat="attachment in cipher.attachments">
<span class="btn-list no-padding" stop-prop stop-click title="{{i18n.deleteAttachment}}" <div class="action-buttons">
ng-click="delete(attachment)"> <span class="btn-list no-padding" stop-prop stop-click title="{{i18n.deleteAttachment}}"
<i class="fa fa-lg fa-trash"></i> ng-click="delete(attachment)">
</span> <i class="fa fa-lg fa-trash"></i>
</span>
</div>
<small class="item-sub-label">{{attachment.sizeName}}</small> <small class="item-sub-label">{{attachment.sizeName}}</small>
<span class="text">{{attachment.fileName}}</span> <span class="text">{{attachment.fileName}}</span>
</div> </div>

View File

@@ -48,7 +48,7 @@
<span class="item-label">{{i18n.username}}</span> <span class="item-label">{{i18n.username}}</span>
<span id="username">{{cipher.login.username}}</span> <span id="username">{{cipher.login.username}}</span>
</div> </div>
<div class="list-section-item" ng-if="cipher.login.password"> <div class="list-section-item wrap" ng-if="cipher.login.password">
<div class="action-buttons"> <div class="action-buttons">
<a class="btn-list" href="" title="{{i18n.togglePassword}}" ng-click="togglePassword()"> <a class="btn-list" href="" title="{{i18n.togglePassword}}" ng-click="togglePassword()">
<i class="fa fa-lg" ng-class="[{'fa-eye': !showPassword}, {'fa-eye-slash': showPassword}]"></i> <i class="fa fa-lg" ng-class="[{'fa-eye': !showPassword}, {'fa-eye-slash': showPassword}]"></i>

View File

@@ -527,7 +527,7 @@ function initCipherService() {
return self.upsert(data); return self.upsert(data);
}).then(function () { }).then(function () {
if (data) { if (data) {
deferred.resolve(new CipherData(data)); deferred.resolve(new Cipher(data));
} }
}); });
}; };
@@ -542,7 +542,7 @@ function initCipherService() {
var self = this, var self = this,
key = null; key = null;
return self.userService.getUserIdPromise().then(function () { return self.userService.getUserIdPromise().then(function (userId) {
key = 'ciphers_' + userId; key = 'ciphers_' + userId;
return self.utilsService.getObjFromStorage(key); return self.utilsService.getObjFromStorage(key);
}).then(function (ciphers) { }).then(function (ciphers) {

View File

@@ -180,7 +180,7 @@ function initFolderService() {
// TODO: Delete folder reference for associated ciphers // TODO: Delete folder reference for associated ciphers
return self.userService.getUserIdPromise().then(function () { return self.userService.getUserIdPromise().then(function (userId) {
key = 'folders_' + userId; key = 'folders_' + userId;
return self.utilsService.getObjFromStorage(key); return self.utilsService.getObjFromStorage(key);
}).then(function (folders) { }).then(function (folders) {