From 723472aca58a0cc4a4cfbbcbaea8267e83341c48 Mon Sep 17 00:00:00 2001 From: Matt Montgomery <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Thu, 3 Sep 2020 16:51:15 -0500 Subject: [PATCH] Complete modifications to work with latest server code --- src/controllers/dashboard/quickconnect.js | 7 +- src/controllers/session/login/index.js | 115 ++++++++++--------- src/controllers/user/quickConnect/index.html | 2 +- src/controllers/user/quickConnect/index.js | 20 +--- src/quickconnect.html | 2 +- src/strings/en-us.json | 2 +- 6 files changed, 71 insertions(+), 77 deletions(-) diff --git a/src/controllers/dashboard/quickconnect.js b/src/controllers/dashboard/quickconnect.js index 9d08bb6b48..012f7b7aa3 100644 --- a/src/controllers/dashboard/quickconnect.js +++ b/src/controllers/dashboard/quickconnect.js @@ -1,4 +1,6 @@ import loading from 'loading'; +import toast from 'toast'; +import globalize from 'globalize'; /* eslint-disable indent */ @@ -32,10 +34,7 @@ import loading from 'loading'; type: 'POST', url: url }, true).then(() => { - require(['toast'], function (toast) { - toast('Settings saved'); - }); - + toast(globalize.translate('SettingsSaved')); setTimeout(updatePage, 500); return true; diff --git a/src/controllers/session/login/index.js b/src/controllers/session/login/index.js index aa5c8cc2d2..c49ed0aee6 100644 --- a/src/controllers/session/login/index.js +++ b/src/controllers/session/login/index.js @@ -19,8 +19,7 @@ import 'emby-checkbox'; var user = result.User; loading.hide(); - Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient); - Dashboard.navigate('home.html'); + onLoginSuccessful(user.Id, result.AccessToken, apiClient); }, function (response) { page.querySelector('#txtManualName').value = ''; page.querySelector('#txtManualPassword').value = ''; @@ -41,6 +40,60 @@ import 'emby-checkbox'; }); } + function authenticateQuickConnect(apiClient) { + let url = apiClient.getUrl('/QuickConnect/Initiate'); + apiClient.getJSON(url).then(function (json) { + if (!json.Secret || !json.Code) { + console.error('Malformed quick connect response', json); + return false; + } + + Dashboard.alert({ + message: globalize.translate('QuickConnectAuthorizeCode', json.Code), + title: globalize.translate('QuickConnect') + }); + + let connectUrl = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret); + + let interval = setInterval(function() { + apiClient.getJSON(connectUrl).then(async function(data) { + if (!data.Authenticated) { + return; + } + + clearInterval(interval); + + let result = await apiClient.quickConnect(data.Authentication); + onLoginSuccessful(result.User.Id, result.AccessToken, apiClient); + }, function (e) { + clearInterval(interval); + + Dashboard.alert({ + message: globalize.translate('QuickConnectDeactivated'), + title: globalize.translate('HeaderError') + }); + + console.error('Unable to login with quick connect', e); + }); + }, 5000, connectUrl); + + return true; + }, function(e) { + Dashboard.alert({ + message: globalize.translate('QuickConnectNotActive'), + title: globalize.translate('HeaderError') + }); + + console.error('Quick connect error: ', e); + return false; + }); + } + + function onLoginSuccessful(id, accessToken, apiClient) { + Dashboard.onServerChanged(id, accessToken, apiClient); + Dashboard.navigate('home.html'); + } + function showManualForm(context, showCancel, focusPassword) { context.querySelector('.chkRememberLogin').checked = appSettings.enableAutoLogin(); context.querySelector('.manualLoginForm').classList.remove('hide'); @@ -154,58 +207,6 @@ import 'emby-checkbox'; }); } - // FIXME: Clicking ok on the code dialog redirects back to the homepage. - function loginQuickConnect() { - let apiClient = getApiClient(); - - let url = apiClient.getUrl('/QuickConnect/Initiate'); - apiClient.getJSON(url).then(function (json) { - if (!json.Secret || !json.Code) { - console.error('Malformed quick connect response', json); - return false; - } - - Dashboard.alert({ - message: globalize.translate('QuickConnectAuthorizeCode', json.Code), - title: globalize.translate('QuickConnect') - }); - - let interval = setInterval(function() { - let connectUrl = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret); - apiClient.getJSON(connectUrl).then(async function(data) { - if (!data.Authenticated) { - return; - } - - clearInterval(interval); - - let result = await apiClient.quickConnect(data.Authentication); - Dashboard.onServerChanged(result.User.Id, result.AccessToken, apiClient); - Dashboard.navigate('home.html'); - }, function (e) { - clearInterval(interval); - - Dashboard.alert({ - message: globalize.translate('QuickConnectDeactivated'), - title: globalize.translate('HeaderError') - }); - - console.error('Unable to login with quick connect', e); - }); - }, 5000); - - return true; - }, function(e) { - Dashboard.alert({ - message: globalize.translate('QuickConnectNotActive'), - title: globalize.translate('HeaderError') - }); - - console.error('Quick connect error: ', e); - return false; - }); - } - view.querySelector('#divUsers').addEventListener('click', function (e) { const card = dom.parentWithClass(e.target, 'card'); const cardContent = card ? card.querySelector('.cardContent') : null; @@ -239,7 +240,11 @@ import 'emby-checkbox'; Dashboard.navigate('forgotpassword.html'); }); view.querySelector('.btnCancel').addEventListener('click', showVisualForm); - view.querySelector('.btnQuick').addEventListener('click', loginQuickConnect); + view.querySelector('.btnQuick').addEventListener('click', function () { + const apiClient = getApiClient(); + authenticateQuickConnect(apiClient); + return false; + }); view.querySelector('.btnManual').addEventListener('click', function () { view.querySelector('#txtManualName').value = ''; showManualForm(view, true); diff --git a/src/controllers/user/quickConnect/index.html b/src/controllers/user/quickConnect/index.html index 5f698a4a6b..15df59ff17 100644 --- a/src/controllers/user/quickConnect/index.html +++ b/src/controllers/user/quickConnect/index.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/controllers/user/quickConnect/index.js b/src/controllers/user/quickConnect/index.js index 2d6f4b15c8..9e8d1a3b31 100644 --- a/src/controllers/user/quickConnect/index.js +++ b/src/controllers/user/quickConnect/index.js @@ -8,10 +8,7 @@ export default function (view) { view.addEventListener('viewshow', function () { let codeElement = view.querySelector('#txtQuickConnectCode'); - quickConnectSettingsInstance = new QuickConnectSettings({ - page: view, - interval: 0 - }); + quickConnectSettingsInstance = new QuickConnectSettings(); view.querySelector('#btnQuickConnectActivate').addEventListener('click', () => { quickConnectSettingsInstance.activate(quickConnectSettingsInstance).then(() => { @@ -30,24 +27,17 @@ export default function (view) { quickConnectSettingsInstance.authorize(code); }); + view.querySelector('.quickConnectSettingsContainer').addEventListener('submit', (e) => { + e.preventDefault(); + }); + renderPage(); }); view.addEventListener('viewbeforehide', function () { if (quickConnectSettingsInstance) { quickConnectSettingsInstance.submit(); } - onDestroy(); }); - view.addEventListener('viewdestroy', function () { - onDestroy(); - }); - - function onDestroy() { - if (quickConnectSettingsInstance) { - quickConnectSettingsInstance.destroy(); - quickConnectSettingsInstance = null; - } - } function renderPage(forceActive = false) { ApiClient.getQuickConnect('Status').then((status) => { diff --git a/src/quickconnect.html b/src/quickconnect.html index 671bb88d77..b5b6d48991 100644 --- a/src/quickconnect.html +++ b/src/quickconnect.html @@ -17,7 +17,7 @@
diff --git a/src/strings/en-us.json b/src/strings/en-us.json index b4442ee0f9..df5b6a36c6 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -1153,7 +1153,7 @@ "Quality": "Quality", "QuickConnect": "Quick Connect", "QuickConnectActivationSuccessful": "Successfully activated", - "QuickConnectAuthorizeCode": "Authorize request {0} to continue", + "QuickConnectAuthorizeCode": "Enter code {0} to login", "QuickConnectAuthorizeSuccess": "Request authorized", "QuickConnectAuthorizeFail": "Unknown quick connect code", "QuickConnectDeactivated": "Quick connect was deactivated before the login request could be approved",