From f761733d0b381e45f78a7b3a9747195e3e622d87 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Jul 2017 14:17:21 -0400 Subject: [PATCH] Show file after upload and reset input --- src/app/services/cipherService.js | 28 +++++++++++++-------- src/app/vault/vaultAttachmentsController.js | 13 +++++++--- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/app/services/cipherService.js b/src/app/services/cipherService.js index b3dce7c56a..9e0aff0186 100644 --- a/src/app/services/cipherService.js +++ b/src/app/services/cipherService.js @@ -15,7 +15,7 @@ angular return unencryptedLogins; }; - _service.decryptLogin = function (encryptedLogin) { + _service.decryptLogin = function (encryptedLogin, isCipher) { if (!encryptedLogin) throw "encryptedLogin is undefined or null"; var key = null; @@ -32,15 +32,19 @@ angular favorite: encryptedLogin.Favorite, edit: encryptedLogin.Edit, organizationUseTotp: encryptedLogin.OrganizationUseTotp, - name: cryptoService.decrypt(encryptedLogin.Name, key), - uri: encryptedLogin.Uri && encryptedLogin.Uri !== '' ? cryptoService.decrypt(encryptedLogin.Uri, key) : null, - username: encryptedLogin.Username && encryptedLogin.Username !== '' ? cryptoService.decrypt(encryptedLogin.Username, key) : null, - password: encryptedLogin.Password && encryptedLogin.Password !== '' ? cryptoService.decrypt(encryptedLogin.Password, key) : null, - notes: encryptedLogin.Notes && encryptedLogin.Notes !== '' ? cryptoService.decrypt(encryptedLogin.Notes, key) : null, - totp: encryptedLogin.Totp && encryptedLogin.Totp !== '' ? cryptoService.decrypt(encryptedLogin.Totp, key) : null, attachments: null }; + var loginData = encryptedLogin.Data || encryptedLogin; + if (loginData) { + login.name = cryptoService.decrypt(loginData.Name, key); + login.uri = loginData.Uri && loginData.Uri !== '' ? cryptoService.decrypt(loginData.Uri, key) : null; + login.username = loginData.Username && loginData.Username !== '' ? cryptoService.decrypt(loginData.Username, key) : null; + login.password = loginData.Password && loginData.Password !== '' ? cryptoService.decrypt(loginData.Password, key) : null; + login.notes = loginData.Notes && loginData.Notes !== '' ? cryptoService.decrypt(loginData.Notes, key) : null; + login.totp = loginData.Totp && loginData.Totp !== '' ? cryptoService.decrypt(loginData.Totp, key) : null; + } + if (!encryptedLogin.Attachments) { return login; } @@ -69,12 +73,16 @@ angular favorite: encryptedCipher.Favorite, edit: encryptedCipher.Edit, organizationUseTotp: encryptedCipher.OrganizationUseTotp, - name: _service.decryptProperty(encryptedCipher.Data.Name, key, false), - username: _service.decryptProperty(encryptedCipher.Data.Username, key, true), - password: _service.decryptProperty(encryptedCipher.Data.Password, key, true), hasAttachments: !!encryptedCipher.Attachments && encryptedCipher.Attachments.length > 0 }; + var loginData = encryptedCipher.Data || encryptedCipher; + if (loginData) { + login.name = cryptoService.decrypt(loginData.Name, key); + login.username = loginData.Username && loginData.Username !== '' ? cryptoService.decrypt(loginData.Username, key) : null; + login.password = loginData.Password && loginData.Password !== '' ? cryptoService.decrypt(loginData.Password, key) : null; + } + return login; }; diff --git a/src/app/vault/vaultAttachmentsController.js b/src/app/vault/vaultAttachmentsController.js index af718e1a4b..d0dd788153 100644 --- a/src/app/vault/vaultAttachmentsController.js +++ b/src/app/vault/vaultAttachmentsController.js @@ -18,7 +18,8 @@ }); $scope.save = function (form) { - var files = document.getElementById('file').files; + var fileEl = document.getElementById('file'); + var files = fileEl.files; if (!files || !files.length) { validationService.addError(form, 'file', 'Select a file.', true); return; @@ -31,9 +32,13 @@ return apiService.ciphers.postAttachment({ id: loginId }, fd).$promise; }).then(function (response) { $analytics.eventTrack('Added Attachment'); - toastr.success('The attachment has been saved.'); - closing = true; - $uibModalInstance.close(true); + $scope.login = cipherService.decryptLogin(response); + + // reset file input + // ref: https://stackoverflow.com/a/20552042 + fileEl.type = ''; + fileEl.type = 'file'; + fileEl.value = ''; }, function (err) { if (err) { validationService.addError(form, 'file', err, true);