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 @@ -