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

179 lines
4.9 KiB
JavaScript
Raw Normal View History

2013-02-20 20:33:05 -05:00
var LoginPage = {
onPageShow: function () {
2014-02-23 22:27:13 -05:00
2013-02-20 20:33:05 -05:00
Dashboard.showLoadingMsg();
2014-02-23 22:27:13 -05:00
var page = this;
var location = window.location.toString().toLowerCase();
var isLocalhost = location.indexOf('localhost') != -1 || location.indexOf('127.0.0.1') != -1;
2014-02-23 22:27:13 -05:00
2014-02-21 00:04:11 -05:00
if (isLocalhost) {
2014-02-23 22:27:13 -05:00
$('.localhostMessage', page).show();
2014-02-21 00:04:11 -05:00
} else {
2014-02-23 22:27:13 -05:00
$('.localhostMessage', page).hide();
2014-02-21 00:04:11 -05:00
}
2013-07-15 21:36:18 -04:00
// Show all users on localhost
2014-02-21 00:04:11 -05:00
var promise1 = !isLocalhost ? ApiClient.getPublicUsers() : ApiClient.getUsers({ IsDisabled: false });
2013-07-08 12:13:21 -04:00
promise1.done(function (users) {
2013-07-08 12:13:21 -04:00
var showManualForm = !users.length || !isLocalhost;
2013-07-08 12:13:21 -04:00
if (showManualForm) {
LoginPage.showManualForm(page);
2013-07-08 12:13:21 -04:00
} else {
LoginPage.showVisualForm(page);
2013-07-08 12:13:21 -04:00
LoginPage.loadUserList(users);
}
Dashboard.hideLoadingMsg();
});
ApiClient.getJSON(ApiClient.getUrl('Branding/Configuration')).done(function (options) {
$('.disclaimer', page).html(options.LoginDisclaimer || '');
});
},
showManualForm: function (page) {
$('.visualLoginForm', page).hide();
$('#manualLoginForm', page).show();
$('#txtManualName', page).focus();
},
showVisualForm: function (page) {
$('.visualLoginForm', page).show();
$('#manualLoginForm', page).hide();
2013-02-20 20:33:05 -05:00
},
getLastSeenText: function (lastActivityDate) {
if (!lastActivityDate) {
return "";
}
return "Last seen " + humane_date(lastActivityDate);
},
getImagePath: function (user) {
if (!user.PrimaryImageTag) {
return "css/images/logindefault.png";
}
return ApiClient.getUserImageUrl(user.Id, {
width: 240,
tag: user.PrimaryImageTag,
type: "Primary"
2013-02-20 20:33:05 -05:00
});
},
authenticateUserLink: function (link) {
LoginPage.authenticateUser(link.getAttribute('data-userid'));
2013-02-20 20:33:05 -05:00
},
authenticateUser: function (userId, password) {
2013-02-20 20:33:05 -05:00
Dashboard.showLoadingMsg();
ApiClient.getUser(userId).done(function (user) {
2013-02-20 20:33:05 -05:00
2013-07-30 21:37:39 -04:00
LoginPage.authenticateUserByName(user.Name, password);
});
},
2014-02-08 15:02:35 -05:00
2013-07-30 21:37:39 -04:00
authenticateUserByName: function (username, password) {
Dashboard.showLoadingMsg();
2013-07-15 21:36:18 -04:00
2013-07-30 21:37:39 -04:00
ApiClient.authenticateUserByName(username, password).done(function (result) {
2013-02-20 20:33:05 -05:00
2013-07-30 21:37:39 -04:00
var user = result.User;
2013-02-20 20:33:05 -05:00
2013-07-30 21:37:39 -04:00
Dashboard.setCurrentUser(user.Id);
2013-07-08 12:13:21 -04:00
2013-07-30 21:37:39 -04:00
if (user.Configuration.IsAdministrator) {
window.location = "dashboard.html?u=" + user.Id;
} else {
window.location = "index.html?u=" + user.Id;
}
}).fail(function () {
2013-07-08 12:13:21 -04:00
2013-07-30 21:37:39 -04:00
$('#pw', '#loginPage').val('');
$('#txtManualName', '#loginPage').val('');
$('#txtManualPassword', '#loginPage').val('');
Dashboard.hideLoadingMsg();
2013-02-20 20:33:05 -05:00
2013-07-30 21:37:39 -04:00
setTimeout(function () {
2014-05-30 15:23:56 -04:00
Dashboard.showError(Globalize.translate('MessageInvalidUser'));
2013-07-30 21:37:39 -04:00
}, 300);
2013-02-20 20:33:05 -05:00
});
2013-02-20 20:33:05 -05:00
},
loadUserList: function (users) {
var html = "";
for (var i = 0, length = users.length; i < length; i++) {
var user = users[i];
var linkId = "lnkUser" + i;
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-userid='" + user.Id + "' href='index.html?u=" + user.Id + "' data-ajax='false' \">";
2013-02-20 20:33:05 -05:00
if (user.PrimaryImageTag) {
var imgUrl = ApiClient.getUserImageUrl(user.Id, {
width: 500,
tag: user.PrimaryImageTag,
type: "Primary"
2013-02-20 20:33:05 -05:00
});
2013-04-25 19:28:01 -04:00
html += '<div class="posterItemImage" style="background-image:url(\'' + imgUrl + '\');"></div>';
}
else {
var background = LibraryBrowser.getMetroColor(user.Id);
html += '<div class="posterItemImage" style="background-color:' + background + ';"></div>';
2013-02-20 20:33:05 -05:00
}
2014-01-01 22:53:27 -05:00
html += '<div class="posterItemText" style="color:#000;">' + user.Name + '</div>';
2013-04-25 19:28:01 -04:00
2014-01-01 22:53:27 -05:00
html += '<div class="posterItemText" style="color:#000;">';
var lastSeen = LoginPage.getLastSeenText(user.LastActivityDate);
if (lastSeen != "") {
html += lastSeen;
}
else {
html += "&nbsp;";
}
2013-02-20 20:33:05 -05:00
html += '</div>';
html += '</a>';
}
$('#divUsers', '#loginPage').html(html);
},
2013-07-08 12:13:21 -04:00
onManualSubmit: function () {
2013-07-30 21:37:39 -04:00
LoginPage.authenticateUserByName($('#txtManualName', '#loginPage').val(), $('#txtManualPassword', '#loginPage').val());
2013-02-20 20:33:05 -05:00
// Disable default form submission
return false;
}
};
$(document).on('pagebeforeshow', "#loginPage", LoginPage.onPageShow);