ソースを参照

fixed plex oauth login

causefx@me.com 6 ヶ月 前
コミット
7b28ac2b0c

+ 2 - 2
api/classes/organizr.class.php

@@ -2383,7 +2383,7 @@ class Organizr
 				$this->settingsOption('select', 'authType', ['id' => 'authSelect', 'label' => 'Authentication Type', 'value' => $this->config['authType'], 'options' => $this->getAuthTypes()]),
 				$this->settingsOption('select', 'authBackend', ['id' => 'authBackendSelect', 'label' => 'Authentication Backend', 'class' => 'backendAuth switchAuth', 'value' => $this->config['authBackend'], 'options' => $this->getAuthBackends()]),
 				$this->settingsOption('token', 'plexToken', ['class' => 'plexAuth switchAuth']),
-				$this->settingsOption('button', '', ['class' => 'getPlexTokenAuth plexAuth switchAuth', 'label' => 'Get Plex Token', 'icon' => 'fa fa-ticket', 'text' => 'Retrieve', 'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, null, \'#settings-main-form [name=plexToken]\')"']),
+				$this->settingsOption('button', '', ['class' => 'getPlexTokenAuth plexAuth switchAuth', 'label' => 'Get Plex Token', 'icon' => 'fa fa-ticket', 'text' => 'Retrieve', 'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, oAuthMaxRetry, null, null, \'#settings-main-form [name=plexToken]\')"']),
 				$this->settingsOption('password-alt', 'plexID', ['class' => 'plexAuth switchAuth', 'label' => 'Plex Machine', 'placeholder' => 'Use Get Plex Machine Button']),
 				$this->settingsOption('button', '', ['class' => 'getPlexMachineAuth plexAuth switchAuth', 'label' => 'Get Plex Machine', 'icon' => 'fa fa-id-badge', 'text' => 'Retrieve', 'attr' => 'onclick="showPlexMachineForm(\'#settings-main-form [name=plexID]\')"']),
 				$this->settingsOption('input', 'plexAdmin', ['label' => 'Plex Admin Username or Email', 'class' => 'plexAuth switchAuth', 'placeholder' => 'Admin username for Plex']),
@@ -2576,7 +2576,7 @@ class Organizr
 			],
 			'Plex' => [
 				$this->settingsOption('token', 'plexToken'),
-				$this->settingsOption('button', '', ['label' => 'Get Plex Token', 'icon' => 'fa fa-ticket', 'text' => 'Retrieve', 'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, null, \'#sso-form [name=plexToken]\')"']),
+				$this->settingsOption('button', '', ['label' => 'Get Plex Token', 'icon' => 'fa fa-ticket', 'text' => 'Retrieve', 'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, oAuthMaxRetry, null, null, \'#sso-form [name=plexToken]\')"']),
 				$this->settingsOption('password-alt', 'plexID', ['label' => 'Plex Machine']),
 				$this->settingsOption('button', '', ['label' => 'Get Plex Machine', 'icon' => 'fa fa-id-badge', 'text' => 'Retrieve', 'attr' => 'onclick="showPlexMachineForm(\'#sso-form [name=plexID]\')"']),
 				$this->settingsOption('input', 'plexAdmin', ['label' => 'Plex Admin Username or Email']),

+ 1 - 1
api/homepage/plex.php

@@ -38,7 +38,7 @@ trait PlexHomepageItem
 					$this->settingsOption('disable-cert-check', 'plexDisableCertCheck'),
 					$this->settingsOption('use-custom-certificate', 'plexUseCustomCertificate'),
 					$this->settingsOption('token', 'plexToken'),
-					$this->settingsOption('button', '', ['label' => 'Get Plex Token', 'icon' => 'fa fa-ticket', 'text' => 'Retrieve', 'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, null, \'#homepage-Plex-form [name=plexToken]\')"']),
+					$this->settingsOption('button', '', ['label' => 'Get Plex Token', 'icon' => 'fa fa-ticket', 'text' => 'Retrieve', 'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, oAuthMaxRetry, null, null, \'#homepage-Plex-form [name=plexToken]\')"']),
 					$this->settingsOption('password-alt', 'plexID', ['label' => 'Plex Machine']),
 					$this->settingsOption('button', '', ['label' => 'Get Plex Machine', 'icon' => 'fa fa-id-badge', 'text' => 'Retrieve', 'attr' => 'onclick="showPlexMachineForm(\'#homepage-Plex-form [name=plexID]\')"']),
 				],

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

@@ -384,7 +384,7 @@ class Invites extends Organizr
 					'label' => 'Get Plex Token',
 					'icon' => 'fa fa-ticket',
 					'text' => 'Retrieve',
-					'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, null, \'#INVITES-settings-items [name=plexToken]\')"'
+					'attr' => 'onclick="PlexOAuth(oAuthSuccess,oAuthError, oAuthMaxRetry, null, null, \'#INVITES-settings-items [name=plexToken]\')"'
 				),
 				array(
 					'type' => 'password-alt',

ファイルの差分が大きいため隠しています
+ 0 - 0
js/custom.min.js


+ 54 - 50
js/functions.js

@@ -8023,44 +8023,42 @@ function buildPiholeItem(array){
 			        card += `<p class="d-inline text-muted">(${key})</p>`;
 		        }
 		        let value = 'Error';
-                    value = e['domains_being_blocked'].map(function (x) {
-                        return `<li>${x.toString()}</li>`;
-                    }).join("");
-		        }
-                card += `<ul class="multi-column" data-toggle="tooltip" title="` + key + `">` + value + `</ul>`;
+                value = e['domains_being_blocked'].map(function (x) {
+                    return `<li>${x.toString()}</li>`;
+                }).join("");
+            }
+            card += `<ul class="multi-column" data-toggle="tooltip" title="` + key + `">` + value + `</ul>`;
 	        }
-        }
-        card += `
+            card += `
+                        </div>
+                        <i class="fa fa-list inline-block" aria-hidden="true"></i>
                     </div>
-                    <i class="fa fa-list inline-block" aria-hidden="true"></i>
                 </div>
             </div>
-        </div>
-        `
-        return card;
-    };
-
-	if(combine) {
-		stats += '<div class="row">'
-		stats += totalQueries(array['data']);
-		stats += totalBlocked(array['data']);
-		stats += percentBlocked(array['data']);
-		stats += domainsBlocked(array['data']);
-		stats += '</div>';
-	} else {
-		for(var key in array['data']) {
-			var data = array['data'][key];
-			obj = {};
-			obj[key] = data;
-			stats += '<div class="row">'
-			stats += totalQueries(obj);
-			stats += totalBlocked(obj);
-			stats += percentBlocked(obj);
-			stats += domainsBlocked(obj);
-			stats += '</div>';
-		};
-	}
+            `
+            return card;
+        }
 
+    if(combine) {
+        stats += '<div class="row">'
+        stats += totalQueries(array['data']);
+        stats += totalBlocked(array['data']);
+        stats += percentBlocked(array['data']);
+        stats += domainsBlocked(array['data']);
+        stats += '</div>';
+    } else {
+        for(var key in array['data']) {
+            var data = array['data'][key];
+            obj = {};
+            obj[key] = data;
+            stats += '<div class="row">'
+            stats += totalQueries(obj);
+            stats += totalBlocked(obj);
+            stats += percentBlocked(obj);
+            stats += domainsBlocked(obj);
+            stats += '</div>';
+        }
+    }
     return stats;
 }
 function homepagePihole(timeout){
@@ -10630,9 +10628,9 @@ getPlexOAuthPin = function () {
     return deferred;
 };
 var polling = null;
-function PlexOAuth(success, error, pre, id = null) {
-    if (typeof pre === "function") {
-        pre()
+function PlexOAuth(successCallback, errorCallback, maxRetryCallback, pollingCallback, preFunction, clientID = null) {
+    if (typeof preFunction === "function") {
+        preFunction()
     }
     closePlexOAuthWindow();
     plex_oauth_window = PopupCenter('', 'Plex-OAuth', 600, 700);
@@ -10656,39 +10654,42 @@ function PlexOAuth(success, error, pre, id = null) {
         };
         plex_oauth_window.location = 'https://app.plex.tv/auth/#!?' + encodeData(oauth_params);
         polling = pin;
+        let maxPollCount = 120;
         (function poll() {
+            maxPollCount--;
             $.ajax({
                 url: 'https://plex.tv/api/v2/pins/' + pin,
                 type: 'GET',
                 headers: x_plex_headers,
                 success: function (data) {
                     if (data.authToken){
+                        polling = null;
                         closePlexOAuthWindow();
-                        if (typeof success === "function") {
-                            success('plex',data.authToken, id)
+                        if (typeof successCallback === "function") {
+                            successCallback('plex', data.authToken, clientID)
                         }
                     }
                 },
-                error: function (jqXHR, textStatus, errorThrown) {
-                    if (textStatus !== "timeout") {
+                complete: function () {
+                    if (maxPollCount <= 0) {
                         closePlexOAuthWindow();
-                        if (typeof error === "function") {
-                            error()
+                        if (typeof maxRetryCallback === "function") {
+                            maxRetryCallback()
                         }
-                    }
-                },
-                complete: function () {
-                    if (!plex_oauth_window.closed && polling === pin){
+                    } else if (polling === pin) {
                         setTimeout(function() {poll()}, 1000);
+                        if (typeof pollingCallback === "function") {
+                            pollingCallback(maxPollCount);
+                        }
                     }
                 },
-                timeout: 10000
+                timeout: 1000
             });
         })();
     }, function () {
         closePlexOAuthWindow();
-        if (typeof error === "function") {
-            error()
+        if (typeof errorCallback === "function") {
+            errorCallback()
         }
     });
 }
@@ -10727,10 +10728,13 @@ function oAuthSuccess(type,token, id = null){
 function oAuthError(){
     messageSingle('',window.lang.translate('Error Connecting to oAuth Provider'),activeInfo.settings.notifications.position,'#FFF','error','5000');
 }
+function oAuthMaxRetry(){
+    messageSingle('',window.lang.translate('Max Retry Error Connecting to oAuth Provider'),activeInfo.settings.notifications.position,'#FFF','error','5000');
+}
 function oAuthStart(type){
     switch(type){
         case 'plex':
-            PlexOAuth(oAuthSuccess,oAuthError);
+            PlexOAuth(oAuthSuccess,oAuthError, oAuthMaxRetry, null, null);
             break;
         default:
             break;

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません