mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 02:48:19 -07:00
Complete modifications to work with latest server code
This commit is contained in:
parent
28928ead7c
commit
723472aca5
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div id="quickConnectPreferencesPage" data-role="page" class="page libraryPage userPreferencesPage noSecondaryNavPage" data-title="${HeaderHome}" data-backbutton="true" style="margin: 0 auto; max-width: 54em">
|
||||
<div id="quickConnectPreferencesPage" data-role="page" class="page libraryPage userPreferencesPage noSecondaryNavPage" data-title="${QuickConnect}" data-backbutton="true" style="margin: 0 auto; max-width: 54em">
|
||||
<button is="emby-button" id="btnQuickConnectActivate" type="button" class="raised button-submit block">
|
||||
<span>${ButtonActivate}</span>
|
||||
</button>
|
||||
|
@ -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) => {
|
||||
|
@ -17,7 +17,7 @@
|
||||
</div>
|
||||
|
||||
<button is="emby-button" id="btnQuickConnectSubmit" type="submit" class="raised button-submit block">
|
||||
<span>${ButtonSave}</span>
|
||||
<span>${Save}</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user