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.
This commit is contained in:
Nils Asmussen 2016-08-20 11:30:12 +02:00
parent 6a1d38d0e9
commit 0f1de0738c
3 changed files with 26 additions and 0 deletions

View File

@ -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')

View File

@ -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,

View File

@ -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!') {