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

Get password from backend if supplied, Resolve bug in resolveEmbyItem()

Cerothen 9 лет назад
Родитель
Сommit
2403df3a40
2 измененных файлов с 19 добавлено и 12 удалено
  1. 18 10
      functions.php
  2. 1 2
      user.php

+ 18 - 10
functions.php

@@ -13,7 +13,7 @@ if (function_exists('ldap_connect')) :
 	// Pass credentials to LDAP backend
 	function plugin_auth_ldap($username, $password) {
 		// returns true or false
-		$ldap = ldap_connect(AUTHBACKENDHOST.(AUTHBACKENDPORT?':'.AUTHBACKENDPORT:'389'));
+		$ldap = ldap_connect(AUTHBACKENDHOST, (AUTHBACKENDPORT ? AUTHBACKENDPORT : '389'));
 		if ($bind = ldap_bind($ldap, AUTHBACKENDDOMAIN.'\\'.$username, $password)) {
 			return true;
 		} else {
@@ -91,7 +91,12 @@ function plugin_auth_emby_local($username, $password) {
 if (function_exists('curl_version')) :
 	// Authenticate Against Emby Local (first) and Emby Connect
 	function plugin_auth_emby_all($username, $password) {
-		return plugin_auth_emby_local($username, $password) || plugin_auth_emby_connect($username, $password);
+		$localResult = plugin_auth_emby_local($username, $password);
+		if ($localResult) {
+			return $localResult;
+		} else {
+			return plugin_auth_emby_connect($username, $password);
+		}
 	}
 	
 	// Authenicate against emby connect
@@ -134,7 +139,10 @@ if (function_exists('curl_version')) :
 				if (isset($result['content'])) {
 					$json = json_decode($result['content'], true);
 					if (is_array($json) && isset($json['AccessToken']) && isset($json['User']) && $json['User']['Id'] == $connectId) {
-						return true;
+						return array(
+							'email' => $json['User']['Email'],
+							'image' => $json['User']['ImageUrl'],
+						);
 					}
 				}
 			}
@@ -418,24 +426,24 @@ function resolveEmbyItem($address, $token, $item) {
 	// Get Item Details
 	$itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&Fields=Overview&api_key='.$token),true)['Items'][0];
 	
-	switch ($item['Type']) {
+	switch ($itemDetails['Type']) {
 		case 'Episode':
-			$title = $item['SeriesName'].': '.$item['Name'].' (Season '.$item['ParentIndexNumber'].': Episode '.$item['IndexNumber'].')';
+			$title = $itemDetails['SeriesName'].': '.$itemDetails['Name'].' (Season '.$itemDetails['ParentIndexNumber'].': Episode '.$itemDetails['IndexNumber'].')';
 			$imageId = $itemDetails['SeriesId'];
 			$width = 100;
 			$image = 'carousel-image season';
 			$style = '';
 			break;
 		case 'MusicAlbum':
-			$title = $item['Name'];
+			$title = $itemDetails['Name'];
 			$imageId = $itemDetails['Id'];
 			$width = 150;
 			$image = 'music';
 			$style = 'left: 160px !important;';
 			break;
 		default:
-			$title = $item['Name'];
-			$imageId = $item['Id'];
+			$title = $itemDetails['Name'];
+			$imageId = $itemDetails['Id'];
 			$width = 100;
 			$image = 'carousel-image movie';
 			$style = '';
@@ -447,7 +455,7 @@ function resolveEmbyItem($address, $token, $item) {
 	}
 	
 	// Assemble Item And Cache Into Array 
-	return '<div class="item"><a href="'.$address.'/web/itemdetails.html?id='.$item['Id'].'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" src="ajax.php?a=emby-image&img='.$imageId.'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption" style="'.$style.'"><h4>'.$title.'</h4><small><em>'.$itemDetails['Overview'].'</em></small></div></div>';
+	return '<div class="item"><a href="'.$address.'/web/itemdetails.html?id='.$itemDetails['Id'].'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" src="ajax.php?a=emby-image&img='.$imageId.'&height='.$height.'&width='.$width.'"></a><div class="carousel-caption" style="'.$style.'"><h4>'.$title.'</h4><small><em>'.$itemDetails['Overview'].'</em></small></div></div>';
 }
 
 // Format item from Plex for Carousel
@@ -888,7 +896,7 @@ function upgradeCheck() {
 		
 		// Refactor
 		$config['database_Location'] = str_replace('//','/',$config['databaseLocation'].'/');
-		$config['user_home'] = $config['databaseLocation'].'users/';
+		$config['user_home'] = $config['database_Location'].'users/';
 		unset($config['databaseLocation']);
 		
 		// Turn Off Emby And Plex Recent

+ 1 - 2
user.php

@@ -607,7 +607,6 @@ EOT;
 						// perform the internal authentication step
 						$query = "SELECT password FROM users WHERE username = '$username'";
 						foreach($this->database->query($query) as $data) {
-							
 							if (password_verify($password, $data["password"])) { // Better
 								$authSuccess = true;
 							} else {
@@ -650,7 +649,7 @@ EOT;
 				} else if (AUTHBACKENDCREATE !== 'false' && $surface) {
 					// Create User
 					$falseByRef = false;
-					$this->register_user($username, "", $sha1, $falseByRef, !$remember);
+					$this->register_user($username, (is_array($authSuccess) && isset($authSuccess['email']) ? $authSuccess['email'] : ''), $sha1, $falseByRef, !$remember);
 				} else {
 					// authentication failed
 					//$this->info("Successful Backend Auth, No User in DB, Create Set to False");