Browse Source

Simplified response of session init

Tobias Reich 9 years ago
parent
commit
d01e894220
5 changed files with 49 additions and 20 deletions
  1. 0 0
      dist/main.js
  2. 11 2
      php/access/Installation.php
  3. 5 0
      php/define.php
  4. 4 4
      php/modules/Session.php
  5. 29 14
      src/scripts/lychee.js

File diff suppressed because it is too large
+ 0 - 0
dist/main.js


+ 11 - 2
php/access/Installation.php

@@ -17,8 +17,7 @@ class Installation extends Access {
 			case 'Database::createConfig':	$this->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);
+
+	}
+
 }
 
 ?>

+ 5 - 0
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/');

+ 4 - 4
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

+ 29 - 14
src/scripts/lychee.js

@@ -41,30 +41,45 @@ lychee.init = function() {
 
 	api.post('Session::init', params, function(data) {
 
-		if (data.loggedIn!==true) {
+		// 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');
-		} else {
-			lychee.username		= data.config.username		|| '';
-			lychee.sorting		= data.config.sorting		|| '';
-			lychee.dropboxKey	= data.config.dropboxKey	|| '';
-			lychee.location		= data.config.location		|| '';
-		}
 
-		// 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();
 

Some files were not shown because too many files changed in this diff