From d01e894220eeacc3becb38afa5a18465269f841d Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Fri, 6 Mar 2015 23:29:55 +0100 Subject: [PATCH] Simplified response of session init --- dist/main.js | Bin 171235 -> 171262 bytes php/access/Installation.php | 13 ++++++++-- php/define.php | 5 ++++ php/modules/Session.php | 8 +++--- src/scripts/lychee.js | 47 ++++++++++++++++++++++++------------ 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/dist/main.js b/dist/main.js index f27e724e98f255c2f25fc0af930a072bc317e3e2..20ca16406688a721825b9d8507bc6b048b3021d5 100644 GIT binary patch delta 147 zcmaF7lk4A3u7(!IEll4T1v1k#jBIUfQ}v2V5=%;pHK%JZG0mLb$joHGT2rHFpff#; znMqsBIyI*_RRO5h5JfE?6O)82T+RSlt|+ynv?xzuI!Fnl&h)2DOnHpf(>F0Qsq^Gi VCTFCk>gD7orf6(`&CK*;1^}`zFC+i} delta 153 zcmeyjlk4$Lu7(!IEll4TC+DZIYo+St4|@dbCreateConfig(); break; # Error - default: exit('Warning: No configuration!'); - return false; break; + default: $this->init(); break; } @@ -33,6 +32,16 @@ class Installation extends Access { } + private function init() { + + $return = array( + 'status' => LYCHEE_STATUS_NOCONFIG + ); + + echo json_encode($return); + + } + } ?> \ No newline at end of file diff --git a/php/define.php b/php/define.php index 80a18ba..fb045f2 100644 --- a/php/define.php +++ b/php/define.php @@ -8,6 +8,11 @@ # Define root define('LYCHEE', substr(__DIR__, 0, -3)); +# Define status +define('LYCHEE_STATUS_NOCONFIG', 0); +define('LYCHEE_STATUS_LOGGEDOUT', 1); +define('LYCHEE_STATUS_LOGGEDIN', 2); + # Define dirs define('LYCHEE_DATA', LYCHEE . 'data/'); define('LYCHEE_SRC', LYCHEE . 'src/'); diff --git a/php/modules/Session.php b/php/modules/Session.php index 74381c5..76e62d4 100755 --- a/php/modules/Session.php +++ b/php/modules/Session.php @@ -55,10 +55,13 @@ class Session extends Module { if ($public===false) { # Logged in - $return['loggedIn'] = true; + $return['status'] = LYCHEE_STATUS_LOGGEDIN; } else { + # Logged out + $return['status'] = LYCHEE_STATUS_LOGGEDOUT; + # Unset unused vars unset($return['config']['username']); unset($return['config']['thumbQuality']); @@ -68,9 +71,6 @@ class Session extends Module { unset($return['config']['location']); unset($return['config']['plugins']); - # Logged out - $return['loggedIn'] = false; - } # Call plugins diff --git a/src/scripts/lychee.js b/src/scripts/lychee.js index d80f32f..416b8cf 100644 --- a/src/scripts/lychee.js +++ b/src/scripts/lychee.js @@ -41,30 +41,45 @@ lychee.init = function() { api.post('Session::init', params, function(data) { - if (data.loggedIn!==true) { - lychee.setMode('public'); - } else { - lychee.username = data.config.username || ''; - lychee.sorting = data.config.sorting || ''; - lychee.dropboxKey = data.config.dropboxKey || ''; - lychee.location = data.config.location || ''; - } + // Check status + // 0 = No configuration + // 1 = Logged out + // 2 = Logged in + + if (data.status===2) { + + // Logged in + + lychee.username = data.config.username || ''; + lychee.sorting = data.config.sorting || ''; + lychee.dropboxKey = data.config.dropboxKey || ''; + lychee.location = data.config.location || ''; + lychee.checkForUpdates = data.config.checkForUpdates || true; + + // No username and password + if (data.config.login===false) settings.createLogin(); + + } else if (data.status===1) { + + // Logged out + + lychee.setMode('public'); + + } else if (data.status===0) { + + // No configuration + + lychee.setMode('public'); - // No configuration - if (data==='Warning: No configuration!') { header.dom().hide(); lychee.content.hide(); $('body').append(build.no_content('cog')); settings.createConfig(); + return true; + } - // No login - if (data.config.login===false) { - settings.createLogin(); - } - - lychee.checkForUpdates = data.config.checkForUpdates; $(window).bind('popstate', lychee.load); lychee.load();