Explorar o código

working on API

Noah Witt %!s(int64=7) %!d(string=hai) anos
pai
achega
31d5cbe66a
Modificáronse 3 ficheiros con 133 adicións e 7 borrados
  1. 54 1
      api/functions/organizr-functions.php
  2. 13 1
      api/index.php
  3. 66 5
      api/plugins/js/invites.js

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

@@ -2064,6 +2064,11 @@ function plexJoinAPI($array)
 	return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
 }
 
+function embyJoinAPI($array)
+{
+	return embyJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
+}
+
 function plexJoin($username, $email, $password)
 {
 	try {
@@ -2107,6 +2112,54 @@ function plexJoin($username, $email, $password)
 	return false;
 }
 
+function embyJoin($username, $email, $password)
+{
+	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" => $password
+		);
+		$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());
+
+		#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());
+
+	} catch (Requests_Exception $e) {
+		writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+	};
+	return false;
+}
+
 function checkFrame($array, $url)
 {
 	if (array_key_exists("x-frame-options", $array)) {
@@ -2254,4 +2307,4 @@ function checkHostPrefix($s)
 		return $s;
 	}
 	return (substr($s, -1, 1) == '\\') ? $s : $s . '\\';
-}
+}

+ 13 - 1
api/index.php

@@ -1232,6 +1232,19 @@ switch ($function) {
 				break;
 		}
 		break;
+		case 'v1_emby_join':
+			switch ($method) {
+				case 'POST':
+					$result['status'] = 'success';
+					$result['statusText'] = 'success';
+					$result['data'] = embyJoinAPI($_POST);
+					break;
+				default:
+					$result['status'] = 'error';
+					$result['statusText'] = 'The function requested is not defined for method: ' . $method;
+					break;
+			}
+			break;
 	case 'v1_token_revoke':
 		switch ($method) {
 			case 'POST':
@@ -1347,4 +1360,3 @@ if ($pretty) {
 } else {
 	exit(safe_json_encode($result, JSON_HEX_QUOT | JSON_HEX_TAG));
 }
-

+ 66 - 5
api/plugins/js/invites.js

@@ -111,6 +111,39 @@ function joinPlex(){
     	});
     }
 }
+
+function joinEmby(){
+    var username = $('#inviteEmbyJoinUsername');
+    var email = $('#inviteEmbyJoinEmail');
+    var password = $('#inviteEmbyJoinPassword');
+    if(username.val() == ''){
+        username.focus();
+        message('Invite Error',' Please Enter Username',activeInfo.settings.notifications.position,'#FFF','warning','5000');
+    }else if(email.val() == ''){
+        email.focus();
+        message('Invite Error',' Please Enter Email',activeInfo.settings.notifications.position,'#FFF','warning','5000');
+    }else if(password.val() == ''){
+        password.focus();
+        message('Invite Error',' Please Enter Passowrd',activeInfo.settings.notifications.position,'#FFF','warning','5000');
+    }
+    if(email.val() !== '' && username.val() !== '' && password.val() !== ''){
+        organizrAPI('POST','api/?v1/emby/join',{username:username.val(), email:email.val(), password:password.val()}).success(function(data) {
+    		var response = JSON.parse(data);
+            if(response.data === true){
+                $('.invite-step-3-emby-no').toggleClass('hidden');
+                $('.invite-step-3-emby-yes').toggleClass('hidden');
+                message('Invite Function',' User Created',activeInfo.settings.notifications.position,'#FFF','success','5000');
+                $('#inviteUsernameInvite').val(username.val());
+                hasPlexUsername();
+            }else{
+                message('Invite Error',' '+response.data,activeInfo.settings.notifications.position,'#FFF','warning','5000');
+            }
+    	}).fail(function(xhr) {
+    		console.error("Organizr Function: API Connection Failed");
+    	});
+    }
+}
+
 function inviteHasAccount(type,value){
     switch (type) {
         case 'plex':
@@ -123,13 +156,13 @@ function inviteHasAccount(type,value){
             }
             break;
         case 'emby' :
-        if(value){
+          if(value){
             $('.invite-step-2').toggleClass('hidden');
-            $('.invite-step-3-plex-yes').toggleClass('hidden');
-        }else{
+            $('.invite-step-3-emby-yes').toggleClass('hidden');
+          }else{
             $('.invite-step-2').toggleClass('hidden');
-            $('.invite-step-3-plex-no').toggleClass('hidden');
-        }
+            $('.invite-step-3-emby-no').toggleClass('hidden');
+          }
           break;
         default:
         alert(type+' is not set up yet');
@@ -397,6 +430,34 @@ $(document).on('click', '.inviteModal', function() {
                         <div class="form-group invite-step-4-plex-accept hidden">
                             <h4 class="" lang="en">You have been invited.  Please goto <a href="https://plex.tv" target="_blank">PLEX.TV</a> and login to accept the invite.  Once you have done that, you may head back here and login with your credentials.</h4>
                         </div>
+                        <!-- Begin Emby Invites -->
+                        <div class="form-group invite-step-3-emby-yes hidden">
+                            <div class="input-group" style="width: 100%;">
+                                <div class="input-group-addon hidden-xs"><i class="ti-user"></i></div>
+                                <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="hasEmbyUsername();">Submit</button>
+                        </div>
+                        <div class="form-group invite-step-3-emby-no hidden">
+                            <div class="input-group" style="width: 100%;">
+                                <div class="input-group-addon hidden-xs"><i class="ti-user"></i></div>
+                                <input type="text" class="form-control" id="invitePlexEmbyUsername" lang="en" placeholder="Username" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" required="">
+                            </div>
+                            <div class="input-group" style="width: 100%;">
+                                <div class="input-group-addon hidden-xs"><i class="ti-email"></i></div>
+                                <input type="text" class="form-control" id="inviteEmbyJoinEmail" lang="en" placeholder="E-Mail" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" required="">
+                            </div>
+                            <div class="input-group" style="width: 100%;">
+                                <div class="input-group-addon hidden-xs"><i class="ti-user"></i></div>
+                                <input type="password" class="form-control" id="inviteEmbyJoinPassword" lang="en" placeholder="Password" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"  required="">
+                            </div>
+                            <br />
+                            <button class="btn btn-block btn-info" onclick="joinEmby();">Submit</button>
+                        </div>
+                        <div class="form-group invite-step-4-emby-accept hidden">
+                            <h4 class="" lang="en">You Have been added to emby!</h4>
+                        </div>
                     </div>
                 </div>
             </div>