From 5e6358efd44bbf38d95fefd8115c51b2870c8419 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 18 Sep 2020 11:06:28 +0200 Subject: [PATCH] Remember public link password on refresh Stores the public link password in sessionStorage so that it survives page refresh. Closing the browser tab or to another tab doesn't preserve it. --- .../src/components/PublicLinks/PublicLink.vue | 20 +++++++++++++++++-- apps/files/src/store/mutations.js | 5 +++++ .../public-link-remember-password-on-refresh | 8 ++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/public-link-remember-password-on-refresh diff --git a/apps/files/src/components/PublicLinks/PublicLink.vue b/apps/files/src/components/PublicLinks/PublicLink.vue index b6eb406720d..f6a13c4d693 100644 --- a/apps/files/src/components/PublicLinks/PublicLink.vue +++ b/apps/files/src/components/PublicLinks/PublicLink.vue @@ -55,6 +55,7 @@ export default { firstTime: true, passwordRequired: false, password: null, + savedPassword: null, inputErrorMessage: null } }, @@ -72,11 +73,23 @@ export default { } }, mounted() { + const publicLinkPassword = sessionStorage.getItem('publicLinkInfo') + if (publicLinkPassword) { + try { + this.savedPassword = atob(publicLinkPassword) + } catch (e) { + console.error('Error decoding saved password, ignoring', e) + // ignore + this.savedPassword = null + } + } + this.resolvePublicLink() }, methods: { ...mapActions('Files', ['setPublicLinkPassword']), resolvePublicLink() { + const password = this.savedPassword || this.password this.loading = true this.inputErrorMessage = null const properties = this.davProperties.concat([ @@ -87,10 +100,10 @@ export default { this.$client.publicFiles.PUBLIC_LINK_SHARE_OWNER ]) this.$client.publicFiles - .list(this.$route.params.token, this.password, properties, '0') + .list(this.$route.params.token, password, properties, '0') .then(files => { this.passwordRequired = false - this.setPublicLinkPassword(this.password) + this.setPublicLinkPassword(password) if (files[0].getProperty(this.$client.publicFiles.PUBLIC_LINK_PERMISSION) === '4') { this.$router.push({ name: 'public-files-drop', @@ -108,6 +121,9 @@ export default { }) }) .catch(error => { + // only attempt once with saved password, it might have changed + // we don't want to populate the form with it! + this.savedPassword = null if (error.statusCode === 401) { this.passwordRequired = true if (!this.firstTime) { diff --git a/apps/files/src/store/mutations.js b/apps/files/src/store/mutations.js index 14c0f601f52..545d6c4fe85 100644 --- a/apps/files/src/store/mutations.js +++ b/apps/files/src/store/mutations.js @@ -227,6 +227,11 @@ export default { }, SET_PUBLIC_LINK_PASSWORD(state, password) { state.publicLinkPassword = password + if (password) { + sessionStorage.setItem('publicLinkInfo', btoa(password)) + } else { + sessionStorage.removeItem('publicLinkInfo') + } }, ADD_ACTION_TO_PROGRESS(state, item) { diff --git a/changelog/unreleased/public-link-remember-password-on-refresh b/changelog/unreleased/public-link-remember-password-on-refresh new file mode 100644 index 00000000000..0bcf57424ab --- /dev/null +++ b/changelog/unreleased/public-link-remember-password-on-refresh @@ -0,0 +1,8 @@ +Enhancement: Remember public link password on page refresh + +When refreshing the page in the file list of a public link share, +the user doesn't need to enter the password again. This only applies for the current page +and the password is forgotten by the browser again upon closing or switching to another site. + +https://github.com/owncloud/phoenix/pull/4083 +https://github.com/owncloud/product/issues/231