1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update web client packager

This commit is contained in:
Luke Pulverenti 2014-10-21 08:42:02 -04:00
parent 0a81db18ed
commit 68ad0f6226
8 changed files with 234 additions and 10 deletions

View file

@ -0,0 +1,110 @@
(function () {
function onLoggedIn() {
ConnectionManager.getServers().done(function (result) {
if (result.length) {
connectToServerInstance(result[0]);
} else {
Dashboard.alert('Coming soon');
}
});
}
function connectToServerInstance(server) {
var url = server.Url;
var exchangeToken = server.AccessKey;
url += "/mediabrowser/Connect/Exchange?format=json&ConnectUserId=" + ConnectionManager.connectUserId();
$.ajax({
type: "GET",
url: url,
dataType: "json",
error: function () {
// Don't show normal dashboard errors
},
headers: {
"X-MediaBrowser-Token": exchangeToken
}
}).done(function (result) {
Dashboard.setCurrentUser(result.LocalUserId, result.AccessToken);
window.location = 'index.html';
}).fail(function (result) {
alert('Error talking to MBS');
});
}
function login(page, username, password) {
var md5 = CryptoJS.MD5(password).toString();
$.ajax({
type: "POST",
url: "https://connect.mediabrowser.tv/service/user/authenticate",
data: {
userName: username,
password: md5
},
dataType: "json",
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
error: function () {
// Don't show normal dashboard errors
}
}).done(function (result) {
ConnectionManager.onConnectAuthenticated(result);
onLoggedIn();
}).fail(function (result) {
Dashboard.alert({
message: Globalize.translate('MessageInvalidUser'),
title: Globalize.translate('HeaderLoginFailure')
});
$('#txtManualPassword', page).val('');
});
}
function submit(page) {
var user = $('#txtManualName', page).val();
var password = $('#txtManualPassword', page).val();
login(page, user, password);
}
window.ConnectLoginPage = {
onSubmit: function () {
var page = $(this).parents('.page');
submit(page);
return false;
}
};
})();

View file

@ -319,7 +319,7 @@
return;
}
var url = window.location.hash || window.location.toString();
var url = window.location.hash || getWindowUrl();
var id = getParameterByName('id', url);

View file

@ -26,7 +26,7 @@
// Chrome seems to have virtualization built-in and can handle large lists easily
var isChrome = $.browser.chrome;
if (window.location.toString().toLowerCase().indexOf('localhost') != -1) {
if (getWindowUrl().toString().toLowerCase().indexOf('localhost') != -1) {
return isChrome ? 200 : 100;
}

View file

@ -39,7 +39,7 @@
isLocalhost: function () {
var location = window.location.toString().toLowerCase();
var location = getWindowUrl().toString().toLowerCase();
return location.indexOf('localhost') != -1 || location.indexOf('127.0.0.1') != -1;
},

View file

@ -147,16 +147,26 @@ var Dashboard = {
Dashboard.getUserPromise = null;
},
isConnectMode: function () {
return getWindowUrl().toLowerCase().indexOf('mediabrowser.tv') != -1;
},
logout: function (logoutWithServer) {
ConnectionManager.logoutFromConnect();
store.removeItem("userId");
store.removeItem("token");
var loginPage = !Dashboard.isConnectMode() ?
'login.html' :
'connectlogin.html';
if (logoutWithServer === false) {
window.location = "login.html";
window.location = loginPage;
} else {
ApiClient.logout().done(function () {
window.location = "login.html";
window.location = loginPage;
});
}
@ -308,14 +318,14 @@ var Dashboard = {
reloadPage: function () {
var currentUrl = window.location.toString().toLowerCase();
var currentUrl = getWindowUrl().toLowerCase();
// If they're on a plugin config page just go back to the dashboard
// The plugin may not have been loaded yet, or could have been uninstalled
if (currentUrl.indexOf('configurationpage') != -1) {
window.location.href = "dashboard.html";
} else {
window.location.href = window.location.href;
window.location.href = getWindowUrl();
}
},
@ -1318,6 +1328,18 @@ $(document).on('pagebeforeshow', ".page", function () {
var page = $(this);
var isConnectMode = Dashboard.isConnectMode();
if (isConnectMode && !page.hasClass('connectLoginPage')) {
if (!ConnectionManager.isLoggedIntoConnect()) {
console.log('Not logged into connect. Redirecting to login.');
Dashboard.logout();
return;
}
}
if (Dashboard.getAccessToken() && Dashboard.getCurrentUserId()) {
Dashboard.getCurrentUser().done(function (user) {
@ -1334,8 +1356,10 @@ $(document).on('pagebeforeshow', ".page", function () {
}
else {
if (this.id !== "loginPage" && !page.hasClass('wizardPage')) {
if (this.id !== "loginPage" && !page.hasClass('wizardPage') && !isConnectMode) {
console.log('Not logged into server. Redirecting to login.');
Dashboard.logout();
return;
}