From 01b3abf587fbd6eebadc05394d61111c714e4a81 Mon Sep 17 00:00:00 2001
From: Tamara Steinwender <tamara.steinwender@tugraz.at>
Date: Mon, 8 Nov 2021 15:45:40 +0100
Subject: [PATCH] Change session storage to local storage in nextcloud
 filepicker

---
 packages/file-handling/src/file-sink.js       |  2 +-
 packages/file-handling/src/file-source.js     |  2 +-
 .../src/nextcloud-file-picker.js              | 24 +++++++++----------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js
index 706aeba4..db3e6790 100644
--- a/packages/file-handling/src/file-sink.js
+++ b/packages/file-handling/src/file-sink.js
@@ -204,7 +204,7 @@ export class FileSink extends ScopedElementsMixin(DbpFileHandlingLitElement) {
         const filePicker = this._('#nextcloud-file-picker');
 
         if (filePicker) {
-            filePicker.checkSessionStorage().then(contents => {
+            filePicker.checkLocalStorage().then(contents => {
                 if (filePicker.webDavClient !== null) {
                     filePicker.loadDirectory(filePicker.directoryPath);
                 }
diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index deb6bc3f..622a2ae9 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -409,7 +409,7 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
         const filePicker = this._('#nextcloud-file-picker');
         // check if element is already in the dom (for example if "dialog-open" attribute is set)
         if (filePicker) {
-            filePicker.checkSessionStorage().then(contents => {
+            filePicker.checkLocalStorage().then(contents => {
                 if (filePicker.webDavClient !== null) {
                     filePicker.loadDirectory(filePicker.directoryPath);
                 }
diff --git a/packages/file-handling/src/nextcloud-file-picker.js b/packages/file-handling/src/nextcloud-file-picker.js
index 8beb5d9a..87cc23f6 100644
--- a/packages/file-handling/src/nextcloud-file-picker.js
+++ b/packages/file-handling/src/nextcloud-file-picker.js
@@ -392,7 +392,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
     }
 
     loginCallback() {
-        this.checkSessionStorage()
+        this.checkLocalStorage()
     }
 
     /**
@@ -421,18 +421,18 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
     /**
      *
      */
-    async checkSessionStorage() {
+    async checkLocalStorage() {
         if (!this.isLoggedIn() || !this.auth)
             return;
         const publicId = this.auth['person-id'];
         const token = parseJwt(this.auth.token);
         const sessionId = token ? token.sid : "";
         if (this.storeSession && sessionId
-            && sessionStorage.getItem("nextcloud-webdav-username" + publicId)
-            && sessionStorage.getItem("nextcloud-webdav-password" + publicId) ){
+            && localStorage.getItem("nextcloud-webdav-username" + publicId)
+            && localStorage.getItem("nextcloud-webdav-password" + publicId) ){
                 try {
-                    const userName = await decrypt(sessionId, sessionStorage.getItem("nextcloud-webdav-username" + publicId));
-                    const password = await decrypt(sessionId, sessionStorage.getItem("nextcloud-webdav-password" + publicId));
+                    const userName = await decrypt(sessionId, localStorage.getItem("nextcloud-webdav-username" + publicId));
+                    const password = await decrypt(sessionId, localStorage.getItem("nextcloud-webdav-password" + publicId));
                     this.webDavClient = createClient(
                         this.webDavUrl + "/" + userName,
                         {
@@ -444,8 +444,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                     this.isPickerActive = true;
                     this.loadDirectory(this.directoryPath);
                 } catch (e) {
-                    sessionStorage.removeItem('nextcloud-webdav-username' + publicId);
-                    sessionStorage.removeItem('nextcloud-webdav-password' + publicId);
+                    localStorage.removeItem('nextcloud-webdav-username' + publicId);
+                    localStorage.removeItem('nextcloud-webdav-password' + publicId);
                     return;
                 }
         }
@@ -528,8 +528,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                     if (sessionId) {
                         const encrytedName = await encrypt(sessionId, data.loginName);
                         const encrytedToken = await encrypt(sessionId, data.token);
-                        sessionStorage.setItem('nextcloud-webdav-username' + publicId, encrytedName);
-                        sessionStorage.setItem('nextcloud-webdav-password' + publicId, encrytedToken);
+                        localStorage.setItem('nextcloud-webdav-username' + publicId, encrytedName);
+                        localStorage.setItem('nextcloud-webdav-password' + publicId, encrytedToken);
 
                     }
                 }
@@ -1235,8 +1235,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
         this.isPickerActive = false;
         if (this.auth) {
             const publicId = this.auth['person-id'];
-            sessionStorage.removeItem('nextcloud-webdav-username' + publicId);
-            sessionStorage.removeItem('nextcloud-webdav-password' + publicId);
+            localStorage.removeItem('nextcloud-webdav-username' + publicId);
+            localStorage.removeItem('nextcloud-webdav-password' + publicId);
         }
     }
 
-- 
GitLab