فهرست منبع

Final

Final Version
Noah Witt 7 سال پیش
والد
کامیت
bf68d9105d
3فایلهای تغییر یافته به همراه53 افزوده شده و 41 حذف شده
  1. 17 10
      api/functions/organizr-functions.php
  2. 2 29
      api/plugins/invites.php
  3. 34 2
      api/plugins/js/invites.js

+ 17 - 10
api/functions/organizr-functions.php

@@ -2177,17 +2177,24 @@ function embyJoin($username, $email, $password)
 		$response = Requests::Post($url, $headers, $GLOBALS['INVITES-EmbyDefaultUserConfig'], array());
 
 		#add emby.media
-		#$headers = array(
-		#	"Accept" => "application/json"
-		#);
-		#$data = array (
-		#	"CurrentPw" => "",
-		#	"Pw" => "abc"
-		#);
-		#$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Connect/Link?api_key=' . $GLOBALS['INVITES-embyApiKey'];
-		#Request::Post($url, $headers, json_encode($data), array());
+		try {
+			#seperate because this is not required
+			$headers = array(
+				"Accept" => "application/json",
+				"X-Emby-Authorization" => $embyAuthHeader
+			);
+			$data = array (
+				"ConnectUsername " => $email
+			);
+			$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Connect/Link';
+			Requests::Post($url, $headers, json_encode($data), array());
+		} catch (Requests_Exception $e)	{
+			writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+		}
+		return(true);
+		//return( "USERID:".$userID);
 	} catch (Requests_Exception $e) {
-		writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+		writeLog('error', 'Emby create Function - Error: ' . $e->getMessage(), 'SYSTEM');
 	};
 	return false;
 }

+ 2 - 29
api/plugins/invites.php

@@ -332,35 +332,8 @@ function inviteAction($username, $action = null, $type = null)
 			break;
 		case 'emby':
 			try {
-				#create user in emby.
-				$headers = array(
-					"Accept" => "application/json"
-				);
-				$data = array ();
-				$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/New?name=' . $username . '&api_key=' . $GLOBALS['INVITES-embyApiKey'];
-				$response = Request::Post($url, $headers, json_encode($data), array());
-				$response = json_decode($response);
-				$userID = $response["Id"];
-
-				#update password
-				$headers = array(
-					"Accept" => "application/json"
-				);
-				$data = array (
-					"CurrentPw" => "",
-					"Pw" => "abc"
-				);
-				$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Password?api_key=' . $GLOBALS['INVITES-embyApiKey'];
-				Request::Post($url, $headers, json_encode($data), array());
-
-				#update config
-				$headers = array(
-					"Accept" => "application/json"
-				);
-				$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Policy?api_key=' . $GLOBALS['INVITES-embyApiKey'];
-				$response = Request::Post($url, $headers, $GLOBALS['INVITES-EmbyDefaultUserConfig'], array());
-
-				#attempt to add emby.media login. Catch this error and do not warn if it fails.
+				#add emby user to sytem
+				return true;
 			} catch (Requests_Exception $e){
 				writeLog('error', 'Emby Invite Function - Error: ' . $e->getMessage(), 'SYSTEM');
 				return false;

+ 34 - 2
api/plugins/js/invites.js

@@ -134,7 +134,7 @@ function joinEmby(){
                 $('.invite-step-3-emby-yes').toggleClass('hidden');
                 message('Invite Function',' User Created',activeInfo.settings.notifications.position,'#FFF','success','5000');
                 $('#inviteUsernameInvite').val(username.val());
-                hasPlexUsername();
+                hasEmbyUsername();
             }else{
                 message('Invite Error',' '+response.data,activeInfo.settings.notifications.position,'#FFF','warning','5000');
             }
@@ -200,6 +200,38 @@ function hasPlexUsername(){
         });
     }
 }
+function hasEmbyUsername(){
+    var code = $('#inviteCodeInput').val().toUpperCase();
+    var username = $('#inviteUsernameInvite');
+    if(username.val() == ''){
+        username.focus();
+        message('Invite Error',' Please Enter Username',activeInfo.settings.notifications.position,'#FFF','warning','5000');
+    }else{
+        var post = {
+            plugin:'Invites/codes',
+            action:'use',
+            code:code,
+            usedby:username.val()
+        };
+        ajaxloader(".content-wrap","in");
+        organizrAPI('POST','api/?v1/plugin',post).success(function(data) {
+            var response = JSON.parse(data);
+            if(response.data === true){
+                $('.invite-step-3-emby-yes').toggleClass('hidden');
+                $('.invite-step-4-emby-accept').toggleClass('hidden');
+                if(local('get', 'invite')){
+            		local('remove', 'invite');
+            	}
+            }else{
+                message('Invite Error',' Code Incorrect',activeInfo.settings.notifications.position,'#FFF','warning','5000');
+            }
+            ajaxloader();;
+        }).fail(function(xhr) {
+            console.error("Organizr Function: API Connection Failed");
+            ajaxloader();
+        });
+    }
+}
 function verifyInvite(){
     var code = $('#inviteCodeInput').val().toUpperCase();
     var post = {
@@ -437,7 +469,7 @@ $(document).on('click', '.inviteModal', function() {
                                 <input type="text" class="form-control" id="inviteUsernameInvite" placeholder="Emby Username" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" required="">
                             </div>
                             <br />
-                            <button class="btn btn-block btn-info" onclick="hasPlexUsername();">Submit</button>
+                            <button class="btn btn-block btn-info" onclick="hasEmbyUsername();">Submit</button>
                         </div>
                         <div class="form-group invite-step-3-emby-no hidden">
                             <div class="input-group" style="width: 100%;">