From 0f1de0738c23538ada2d798aff0afe43b97c3b85 Mon Sep 17 00:00:00 2001 From: Nils Asmussen Date: Sat, 20 Aug 2016 11:30:12 +0200 Subject: [PATCH] Redirect to start page if we were logged out. Previously, Lychee simply stopped working if, e.g., our cookie expired without letting the user know what went wrong. Now, the user gets redirected to the start page instead. This happens if: 1) viewing a private album/photo is denied in private mode 2) the requested function on the served doesn't exist The second case can also happen due to a bug in Lychee, though. --- src/scripts/album.js | 6 ++++++ src/scripts/lychee.js | 12 ++++++++++++ src/scripts/photo.js | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/src/scripts/album.js b/src/scripts/album.js index 544eb25..4a2a427 100644 --- a/src/scripts/album.js +++ b/src/scripts/album.js @@ -49,6 +49,12 @@ album.load = function(albumID, refresh = false) { if (data==='Warning: Album private!') { + // if we were in private mode, restart lychee. maybe the cookie has expired + if (!lychee.publicMode) { + lychee.restart() + return false + } + if (document.location.hash.replace('#', '').split('/')[1]!=undefined) { // Display photo only lychee.setMode('view') diff --git a/src/scripts/lychee.js b/src/scripts/lychee.js index 105e5ba..2c4b4e5 100644 --- a/src/scripts/lychee.js +++ b/src/scripts/lychee.js @@ -144,6 +144,12 @@ lychee.logout = function() { } +lychee.restart = function() { + + document.location.href = '' + +} + lychee.goto = function(url = '') { url = '#' + url @@ -418,6 +424,12 @@ lychee.html = function(literalSections, ...substs) { lychee.error = function(errorThrown, params, data) { + // if the requested function was not found, our cookie has probably expired + if (data.startsWith('Error: Function not found!')) { + lychee.restart() + return + } + console.error({ description : errorThrown, params : params, diff --git a/src/scripts/photo.js b/src/scripts/photo.js index 860ad68..dc6bdd7 100644 --- a/src/scripts/photo.js +++ b/src/scripts/photo.js @@ -48,9 +48,17 @@ photo.load = function(photoID, albumID) { api.post('Photo::get', params, function(data) { if (data==='Warning: Photo private!') { + + // if we were in private mode, restart lychee. maybe the cookie has expired + if (!lychee.publicMode) { + lychee.restart() + return false + } + lychee.content.show() lychee.goto() return false + } if (data==='Warning: Wrong password!') {