Просмотр исходного кода

Case Insensitive Logins, Config Improvements, Bugfixes

Cerothen 9 лет назад
Родитель
Сommit
8c5ed66ce0
4 измененных файлов с 37 добавлено и 17 удалено
  1. 0 3
      ajax.php
  2. 31 2
      functions.php
  3. 1 2
      index.php
  4. 5 10
      user.php

+ 0 - 3
ajax.php

@@ -5,9 +5,6 @@ require_once('functions.php');
 // Upgrade environment
 upgradeCheck();
 
-// Define Version
- define('INSTALLEDVERSION', '1.31');
-
 // Lazyload settings
 $databaseConfig = configLazy('config/config.php');
 

+ 31 - 2
functions.php

@@ -1,5 +1,10 @@
 <?php
 
+// ===================================
+// Define Version
+ define('INSTALLEDVERSION', '1.323');
+// ===================================
+
 // Debugging output functions
 function debug_out($variable, $die = false) {
 	$trace = debug_backtrace()[0];
@@ -715,7 +720,16 @@ function randString($length = 10) {
 
 // Create config file in the return syntax
 function createConfig($array, $path = 'config/config.php', $nest = 0) {
+	// Define Initial Value
 	$output = array();
+	
+	// Sort Items
+	ksort($array);
+	
+	// Unset the current version
+	unset($array['CONFIG_VERSION']);
+	
+	// Process Settings
 	foreach ($array as $k => $v) {
 		$allowCommit = true;
 		switch (gettype($v)) {
@@ -743,6 +757,12 @@ function createConfig($array, $path = 'config/config.php', $nest = 0) {
 		}
 	}
 	
+	if (!$nest) {
+		// Inject Current Version
+		$output[] = "\t".'"CONFIG_VERSION" => "'.INSTALLEDVERSION.'"';
+	}
+	
+	// Build output
 	$output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n",$output)."\n".str_repeat("\t",$nest).')'.(!$nest?';':'');
 	
 	if (!$nest && $path) {
@@ -831,7 +851,7 @@ function defineConfig($array, $anyCase = true, $nest_prefix = false) {
 }
 
 // This function exists only because I am lazy
-function configLazy($path) {
+function configLazy($path = null) {
 	$config = fillDefaultConfig(loadConfig($path));
 	if (is_array($config)) {
 		defineConfig($config);
@@ -911,7 +931,7 @@ function upgradeCheck() {
 		$config["headphonesURL"] = $config["headphonesURL"].(!empty($config["headphonesPort"])?':'.$config["headphonesPort"]:'');
 		unset($config["headphonesPort"]);
 		
-		$createConfigSuccess = createConfig($config, 'config/config.php', $nest = 0);
+		$createConfigSuccess = createConfig($config);
 		
 		// Create new config
 		if ($createConfigSuccess) {
@@ -925,6 +945,15 @@ function upgradeCheck() {
 		}
 	}
 	
+	// Upgrade
+	$config = loadConfig();
+	if (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33') {
+		$config['user_home'] = $config['database_Location'].'users/';
+		unset($config['USER_HOME']);
+		$createConfigSuccess = createConfig($config);
+	}
+	unset($config);
+	
 	return true;
 }
 

+ 1 - 2
index.php

@@ -44,7 +44,7 @@ if(!file_exists('config/config.php')) {
 		if (isset($_POST['database_Location'])) {
 			$_POST['database_Location'] = str_replace('//','/',$_POST['database_Location'].'/');
             if(substr($_POST['database_Location'], -1) != "/") : $_POST['database_Location'] = $_POST['database_Location'] . "/"; endif;
-			$_POST['USER_HOME'] = $_POST['database_Location'].'users/';
+			$_POST['user_home'] = $_POST['database_Location'].'users/';
 		}
 		if (file_exists($_POST['database_Location'])) {
 			updateConfig($_POST);
@@ -194,7 +194,6 @@ if(!defined('AUTOHIDE')) : define('AUTOHIDE', 'false'); endif;
 if(!defined('ENABLEMAIL')) : define('ENABLEMAIL', 'false'); endif;
 if(!defined('CUSTOMCSS')) : define('CUSTOMCSS', 'false'); endif;
 if(!defined('LOADINGSCREEN')) : define('LOADINGSCREEN', 'true'); endif;
-if(!defined('INSTALLEDVERSION')) : define('INSTALLEDVERSION', 'Awaiting-Install...'); endif;
 if(!isset($notifyExplode)) :
 
     $notifyExplode = array("bar","slidetop");

+ 5 - 10
user.php

@@ -10,9 +10,6 @@
 	
 	// Include functions if not already included
 	require_once('functions.php');
-	
-	// Define Version
-	 define('INSTALLEDVERSION', '1.323');
 	 
     // Autoload frameworks
 	require_once(__DIR__ . '/vendor/autoload.php');
@@ -549,7 +546,7 @@ EOT;
 
 			// This user can be registered
 			$insert = "INSERT INTO users (username, email, password, token, role, active, last) ";
-			$insert .= "VALUES ('$username', '$email', '$dbpassword', '', '$newRole', 'false', '') ";
+			$insert .= "VALUES ('".strtolower($username)."', '$email', '$dbpassword', '', '$newRole', 'false', '') ";
 			$this->database->exec($insert);
 			$query = "SELECT * FROM users WHERE username = '$username'";
 			foreach($this->database->query($query) as $data) {
@@ -605,7 +602,7 @@ EOT;
 				default: // Internal
 					if (!$authSuccess) {
 						// perform the internal authentication step
-						$query = "SELECT password FROM users WHERE username = '$username'";
+						$query = "SELECT password FROM users WHERE LOWER(username) = '".strtolower($username)."'";
 						foreach($this->database->query($query) as $data) {
 							if (password_verify($password, $data["password"])) { // Better
 								$authSuccess = true;
@@ -622,13 +619,11 @@ EOT;
 			
 			if ($authSuccess) {
 				// Make sure user exists in database
-				$query = "SELECT username FROM users WHERE username = '$username'";
+				$query = "SELECT username FROM users WHERE LOWER(username) = '".strtolower($username)."'";
 				$userExists = false;
 				foreach($this->database->query($query) as $data) {
-					if ($data['username'] == $username) {
-						$userExists = true;
-						break;
-					}
+					$userExists = true;
+					break;
 				}
 				
 				if ($userExists) {