diff --git a/src/Vault/wwwroot/app/services/apiService.js b/src/Vault/wwwroot/app/services/apiService.js index 0e825e1ad0..fb76234f7f 100644 --- a/src/Vault/wwwroot/app/services/apiService.js +++ b/src/Vault/wwwroot/app/services/apiService.js @@ -21,10 +21,6 @@ del: { method: 'DELETE', params: { id: '@id' } } }); - _service.ciphers = $resource(_apiUri + '/ciphers/:id', {}, { - putMany: { url: _apiUri + '/ciphers/many', method: 'PUT', params: {} } - }); - _service.accounts = $resource(_apiUri + '/accounts', {}, { registerToken: { url: _apiUri + '/accounts/register-token', method: 'POST', params: {} }, register: { url: _apiUri + '/accounts/register', method: 'POST', params: {} }, @@ -36,7 +32,8 @@ getTwoFactor: { url: _apiUri + '/accounts/two-factor', method: 'GET', params: {} }, putTwoFactor: { url: _apiUri + '/accounts/two-factor', method: 'PUT', params: {} }, postPasswordHint: { url: _apiUri + '/accounts/password-hint', method: 'POST', params: {} }, - putSecurityStamp: { url: _apiUri + '/accounts/security-stamp', method: 'PUT', params: {} } + putSecurityStamp: { url: _apiUri + '/accounts/security-stamp', method: 'PUT', params: {} }, + 'import': { url: _apiUri + '/accounts/import', method: 'POST', params: {} } }); _service.auth = $resource(_apiUri + '/auth', {}, { diff --git a/src/Vault/wwwroot/app/services/cipherService.js b/src/Vault/wwwroot/app/services/cipherService.js index ffb98e1fd6..811041924a 100644 --- a/src/Vault/wwwroot/app/services/cipherService.js +++ b/src/Vault/wwwroot/app/services/cipherService.js @@ -24,7 +24,7 @@ angular folderId: encryptedSite.FolderId, name: cryptoService.decrypt(encryptedSite.Name), uri: cryptoService.decrypt(encryptedSite.Uri), - username: cryptoService.decrypt(encryptedSite.Username), + username: encryptedSite.Username && encryptedSite.Username !== '' ? cryptoService.decrypt(encryptedSite.Username) : null, password: cryptoService.decrypt(encryptedSite.Password), notes: encryptedSite.Notes && encryptedSite.Notes !== '' ? cryptoService.decrypt(encryptedSite.Notes) : null }; @@ -79,7 +79,7 @@ angular folderId: unencryptedSite.folderId === '' ? null : unencryptedSite.folderId, uri: cryptoService.encrypt(unencryptedSite.uri, key), name: cryptoService.encrypt(unencryptedSite.name, key), - username: cryptoService.encrypt(unencryptedSite.username, key), + username: !unencryptedSite.username || unencryptedSite.username === '' ? null : cryptoService.encrypt(unencryptedSite.username, key), password: cryptoService.encrypt(unencryptedSite.password, key), notes: !unencryptedSite.notes || unencryptedSite.notes === '' ? null : cryptoService.encrypt(unencryptedSite.notes, key) }; diff --git a/src/Vault/wwwroot/app/services/validationService.js b/src/Vault/wwwroot/app/services/validationService.js index c8f432081c..d328948fb2 100644 --- a/src/Vault/wwwroot/app/services/validationService.js +++ b/src/Vault/wwwroot/app/services/validationService.js @@ -41,7 +41,18 @@ form.$errors = []; } - form.$errors.push(errorMessage); + var pushError = true; + for (var i = 0; i < form.$errors.length; i++) { + if (form.$errors[i] == errorMessage) { + pushError = false; + break; + } + } + + if (pushError) { + form.$errors.push(errorMessage); + } + if (key && key !== '' && form[key] && form[key].$registerApiError) { form[key].$registerApiError(); } diff --git a/src/Vault/wwwroot/app/settings/settingsChangeEmailController.js b/src/Vault/wwwroot/app/settings/settingsChangeEmailController.js index f2ef340b84..eefb1d7e96 100644 --- a/src/Vault/wwwroot/app/settings/settingsChangeEmailController.js +++ b/src/Vault/wwwroot/app/settings/settingsChangeEmailController.js @@ -50,7 +50,7 @@ $uibModalInstance.dismiss('cancel'); authService.logOut(); $state.go('frontend.login.info').then(function () { - toastr.success('Please log back in.', 'Email Changed') + toastr.success('Please log back in.', 'Email Changed'); }); }, function () { // TODO: recovery mode diff --git a/src/Vault/wwwroot/app/settings/settingsChangePasswordController.js b/src/Vault/wwwroot/app/settings/settingsChangePasswordController.js index 844f540a35..f00519dd7b 100644 --- a/src/Vault/wwwroot/app/settings/settingsChangePasswordController.js +++ b/src/Vault/wwwroot/app/settings/settingsChangePasswordController.js @@ -37,7 +37,7 @@ $uibModalInstance.dismiss('cancel'); authService.logOut(); $state.go('frontend.login.info').then(function () { - toastr.success('Please log back in.', 'Master Password Changed') + toastr.success('Please log back in.', 'Master Password Changed'); }); }, function () { // TODO: recovery mode diff --git a/src/Vault/wwwroot/app/settings/settingsSessionsController.js b/src/Vault/wwwroot/app/settings/settingsSessionsController.js index 87fb77e3fa..c649c91490 100644 --- a/src/Vault/wwwroot/app/settings/settingsSessionsController.js +++ b/src/Vault/wwwroot/app/settings/settingsSessionsController.js @@ -11,7 +11,7 @@ $uibModalInstance.dismiss('cancel'); authService.logOut(); $state.go('frontend.login.info').then(function () { - toastr.success('Please log back in.', 'All Sessions Deauthorized') + toastr.success('Please log back in.', 'All Sessions Deauthorized'); }); }).$promise; }; diff --git a/src/Vault/wwwroot/app/settings/settingsTwoFactorController.js b/src/Vault/wwwroot/app/settings/settingsTwoFactorController.js index b621624aa1..b76da478a2 100644 --- a/src/Vault/wwwroot/app/settings/settingsTwoFactorController.js +++ b/src/Vault/wwwroot/app/settings/settingsTwoFactorController.js @@ -9,7 +9,7 @@ $scope.account = _profile.email; $scope.enabled = function () { return _profile.extended && _profile.extended.twoFactorEnabled; - } + }; $scope.auth = function (model) { _masterPasswordHash = cryptoService.hashPassword(model.masterPassword); diff --git a/src/Vault/wwwroot/app/tools/toolsImportController.js b/src/Vault/wwwroot/app/tools/toolsImportController.js index eb2b7433ef..aa1b5300df 100644 --- a/src/Vault/wwwroot/app/tools/toolsImportController.js +++ b/src/Vault/wwwroot/app/tools/toolsImportController.js @@ -1,7 +1,97 @@ angular .module('bit.tools') - .controller('toolsImportController', function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, $q, toastr) { + .controller('toolsImportController', function ($scope, $state, apiService, $uibModalInstance, cryptoService, cipherService, toastr) { + $scope.model = { source: 'local' }; + + $scope.import = function (model) { + var file = document.getElementById('file').files[0]; + + // local + if (model.source == 'local') { + Papa.parse(file, { + header: true, + complete: function (results) { + console.log(results); + } + }); + } // lastpass + else if (model.source == 'lastpass') { + Papa.parse(file, { + header: true, + complete: function (results) { + var folders = [], + sites = [], + siteRelationships = []; + + angular.forEach(results.data, function (value, key) { + if (!value.url || value.url === '') { + return; + } + + var folderIndex = folders.length, + siteIndex = sites.length, + hasFolder = value.grouping && value.grouping !== '' && value.grouping != '(none)', + addFolder = hasFolder; + + if (hasFolder) { + for (var i = 0; i < folders.length; i++) { + if (folders[i].name == value.grouping) { + addFolder = false; + folderIndex = i; + break; + } + } + } + + sites.push({ + uri: value.url, + username: value.username && value.username !== '' ? value.username : null, + password: value.password, + notes: value.extra && value.extra !== '' ? value.extra : null, + name: value.name + }); + + if (addFolder) { + folders.push({ + name: value.grouping + }); + } + + if (hasFolder) { + var relationship = { + key: siteIndex, + value: folderIndex + }; + siteRelationships.push(relationship); + } + }); + + doImport(folders, sites, siteRelationships); + } + }); + } + else { + // source not supported + } + }; + + function doImport(folders, sites, siteRelationships) { + $scope.importPromise = apiService.tools.import({ + folders: cipherService.encryptFolders(folders, cryptoService.getKey()), + sites: cipherService.encryptSites(sites, cryptoService.getKey()), + siteRelationships: siteRelationships + }, function () { + $uibModalInstance.dismiss('cancel'); + $state.go('backend.vault').then(function () { + toastr.success('Data has been successfully imported into your vault.', 'Import Success'); + }); + }, function () { + $uibModalInstance.dismiss('cancel'); + toastr.error('Something went wrong.', 'Oh No!'); + }).$promise; + } + $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; diff --git a/src/Vault/wwwroot/app/tools/views/toolsImport.html b/src/Vault/wwwroot/app/tools/views/toolsImport.html index 44f283c098..a406032735 100644 --- a/src/Vault/wwwroot/app/tools/views/toolsImport.html +++ b/src/Vault/wwwroot/app/tools/views/toolsImport.html @@ -10,7 +10,17 @@