Browse Source

Change to Template User Stratagy

Noah Witt 7 years ago
parent
commit
5a58d1728d
3 changed files with 52 additions and 6 deletions
  1. 47 1
      api/functions/organizr-functions.php
  2. 1 1
      api/plugins/config/invites.php
  3. 4 4
      api/plugins/invites.php

+ 47 - 1
api/functions/organizr-functions.php

@@ -2174,7 +2174,7 @@ function embyJoin($username, $email, $password)
 			"Content-Type" => "application/json"
 		);
 		$url =  $GLOBALS['embyURL'] . '/emby/Users/' . $userID . '/Policy?api_key=' . $GLOBALS['embyToken'];
-		$response = Requests::Post($url, $headers, $GLOBALS['INVITES-EmbyDefaultUserConfig'], array());
+		$response = Requests::Post($url, $headers, getEmbyTemplateUserJson(), array());
 
 		#add emby.media
 		try {
@@ -2221,6 +2221,52 @@ function checkFrame($array, $url)
 	}
 }
 
+/*loads users from emby and returns a correctly formated policy for a new user.
+*/
+function getEmbyTemplateUserJson()
+{
+	$headers = array(
+		"Accept" => "application/json"
+	);
+	$data = array ();
+	$url =  $GLOBALS['embyURL'] . '/emby/Users?api_key=' . $GLOBALS['embyToken'];
+	$response = Requests::Get($url, $headers, array());
+	$response = $response->body;
+	$response = json_decode($response, true);
+
+	//error_Log("response ".json_encode($response));
+	writeLog('error', 'userList:'.json_encode($response), 'SYSTEM');
+	//$correct stores the template users object
+	$correct = null;
+
+	foreach($response as $element)
+	{
+		if($element['Name'] == $GLOBALS['INVITES-EmbyTemplate'])
+		{
+			$correct = $element;
+		}
+	}
+	writeLog('error', 'Correct user:'.json_encode($correct), 'SYSTEM');
+	if($correct == null)
+	{
+		//return empty JSON if user incorectly configured template
+		return "{}";
+	}
+
+	//select policy section and remove possibly dangeours rows.
+
+
+	$policy = $correct['Policy'];
+
+	//writeLog('error', 'policy update'.$policy, 'SYSTEM');
+	unset($policy['AuthenticationProviderId']);
+	unset($policy['InvalidLoginAttemptCount']);
+	unset($policy['DisablePremiumFeatures']);
+	unset($policy['DisablePremiumFeatures']);
+
+	return(json_encode($policy));
+}
+
 function frameTest($url)
 {
 	$array = array_change_key_case(get_headers(qualifyURL($url), 1));

+ 1 - 1
api/plugins/config/invites.php

@@ -3,5 +3,5 @@ return array(
 	'INVITES-enabled' => false,
 	'INVITES-type-include' => 'plex',
 	'INVITES-plexLibraries' => '',
-	'INVITES-EmbyDefaultUserConfig' => ''
+	'INVITES-EmbyTemplate' => ''
 );

+ 4 - 4
api/plugins/invites.php

@@ -242,10 +242,10 @@ function invitesGetSettings()
 			),
 			array(
 				'type' => 'text',
-				'name' => 'INVITES-EmbyDefaultUserConfig',
-				'label' => 'Emby Default User Config JSON',
-				'value' => $GLOBALS['INVITES-EmbyDefaultUserConfig'],
-				'placeholder' => '{...}'
+				'name' => 'INVITES-EmbyTemplate',
+				'label' => 'Emby User to be used as template for new users',
+				'value' => $GLOBALS['INVITES-EmbyTemplate'],
+				'placeholder' => 'AdamSmith'
 			)
 		),
 		'FYI' => array(