mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Modified to work with latest server code
This commit is contained in:
parent
9476edcbe2
commit
28928ead7c
5 changed files with 51 additions and 89 deletions
|
@ -5,22 +5,15 @@ export class QuickConnectSettings {
|
|||
constructor() { }
|
||||
|
||||
authorize(code) {
|
||||
let url = ApiClient.getUrl('/QuickConnect/Authorize');
|
||||
let url = ApiClient.getUrl('/QuickConnect/Authorize?Code=' + code);
|
||||
ApiClient.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
data: {
|
||||
'Code': code
|
||||
}
|
||||
url: url
|
||||
}, true).then(() => {
|
||||
require(['toast'], function (toast) {
|
||||
toast(globalize.translate('QuickConnectAuthorizeSuccess'));
|
||||
});
|
||||
}).catch(() => {
|
||||
require(['toast'], function (toast) {
|
||||
toast(globalize.translate('QuickConnectAuthorizeFail'));
|
||||
});
|
||||
});
|
||||
|
||||
// prevent bubbling
|
||||
return false;
|
||||
|
@ -30,28 +23,16 @@ export class QuickConnectSettings {
|
|||
let url = ApiClient.getUrl('/QuickConnect/Activate');
|
||||
return ApiClient.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json'
|
||||
}).then((json) => {
|
||||
let message = json.Error;
|
||||
|
||||
if (message && message !== '') {
|
||||
console.error('Error activating quick connect. Error: ', json.Error);
|
||||
|
||||
Dashboard.alert({
|
||||
title: 'Unable to activate quick connect',
|
||||
message: message
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
url: url
|
||||
}).then(() => {
|
||||
toast(globalize.translate('QuickConnectActivationSuccessful'));
|
||||
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
console.error('Error activating quick connect. Error:', e);
|
||||
Dashboard.alert({
|
||||
title: globalize.translate('HeaderError'),
|
||||
message: globalize.translate('DefaultErrorMessage')
|
||||
});
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,13 +26,10 @@ import loading from 'loading';
|
|||
|
||||
let newStatus = page.querySelector('#chkQuickConnectAvailable').checked ? 'Available' : 'Unavailable';
|
||||
|
||||
let url = ApiClient.getUrl('/QuickConnect/Available');
|
||||
let url = ApiClient.getUrl('/QuickConnect/Available?Status=' + newStatus);
|
||||
|
||||
ApiClient.ajax({
|
||||
type: 'POST',
|
||||
data: {
|
||||
'Status': newStatus
|
||||
},
|
||||
url: url
|
||||
}, true).then(() => {
|
||||
require(['toast'], function (toast) {
|
||||
|
|
|
@ -154,69 +154,54 @@ import 'emby-checkbox';
|
|||
});
|
||||
}
|
||||
|
||||
// FIXME: Clicking ok on the code dialog redirects back to the homepage.
|
||||
function loginQuickConnect() {
|
||||
let apiClient = getApiClient();
|
||||
let friendlyName = navigator.userAgent;
|
||||
|
||||
let url = apiClient.getUrl('/QuickConnect/Initiate?FriendlyName=' + friendlyName);
|
||||
apiClient.getJSON(url)
|
||||
.then(json => {
|
||||
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')
|
||||
message: globalize.translate('QuickConnectAuthorizeCode', json.Code),
|
||||
title: globalize.translate('QuickConnect')
|
||||
});
|
||||
|
||||
loading.show();
|
||||
|
||||
let interval = setInterval(async function() {
|
||||
try {
|
||||
let interval = setInterval(function() {
|
||||
let connectUrl = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret);
|
||||
let data = await apiClient.getJSON(connectUrl);
|
||||
if (data.Authenticated) {
|
||||
let result = await apiClient.quickConnect(data.Authentication);
|
||||
let user = result.User;
|
||||
let serverId = getParameterByName('serverid');
|
||||
let newUrl = 'home.html';
|
||||
|
||||
if (user.Policy.IsAdministrator && !serverId) {
|
||||
newUrl = 'dashboard.html';
|
||||
apiClient.getJSON(connectUrl).then(async function(data) {
|
||||
if (!data.Authenticated) {
|
||||
return;
|
||||
}
|
||||
|
||||
loading.hide();
|
||||
Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient);
|
||||
Dashboard.navigate(newUrl);
|
||||
clearInterval(interval);
|
||||
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
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: 'Quick connect was deactivated before the login request could be approved',
|
||||
title: 'Unexpected error'
|
||||
message: globalize.translate('QuickConnectDeactivated'),
|
||||
title: globalize.translate('HeaderError')
|
||||
});
|
||||
|
||||
console.error('Unable to login with quick connect', e);
|
||||
clearInterval(interval);
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
}, function(e) {
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('QuickConnectNotActive'),
|
||||
title: 'Error'
|
||||
message: globalize.translate('QuickConnectNotActive'),
|
||||
title: globalize.translate('HeaderError')
|
||||
});
|
||||
|
||||
console.error('Quick connect error: ', e);
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -73,6 +73,4 @@ export default function (view) {
|
|||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
renderPage();
|
||||
}
|
||||
|
|
|
@ -1156,6 +1156,7 @@
|
|||
"QuickConnectAuthorizeCode": "Authorize request {0} to continue",
|
||||
"QuickConnectAuthorizeSuccess": "Request authorized",
|
||||
"QuickConnectAuthorizeFail": "Unknown quick connect code",
|
||||
"QuickConnectDeactivated": "Quick connect was deactivated before the login request could be approved",
|
||||
"QuickConnectDescription": "To sign in with quick connect, select the Quick Connect button on the device you are logging in from and enter the displayed code below.",
|
||||
"QuickConnectInvalidCode": "Invalid quick connect code",
|
||||
"QuickConnectNotAvailable": "Ask your server administrator to enable quick connect",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue