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

193 lines
5.4 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;
2013-07-15 21:36:18 -04:00
// Show all users on localhost
2014-07-07 21:41:03 -04:00
var promise1 = ApiClient.getPublicUsers();
2013-07-08 12:13:21 -04:00
promise1.done(function (users) {
2013-07-08 12:13:21 -04:00
2014-07-07 21:41:03 -04:00
var showManualForm = !users.length;
2013-07-08 12:13:21 -04:00
if (showManualForm) {
2014-07-07 21:41:03 -04:00
LoginPage.showManualForm(page, false);
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 || '');
});
},
cancelLogin: function () {
2014-07-07 21:41:03 -04:00
LoginPage.showVisualForm($.mobile.activePage);
},
showManualForm: function (page, showCancel) {
$('.visualLoginForm', page).hide();
$('#manualLoginForm', page).show();
$('#txtManualName', page).focus();
2014-07-07 21:41:03 -04:00
if (showCancel) {
$('.btnCancel', page).show();
} else {
$('.btnCancel', page).hide();
}
},
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
});
},
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
2014-07-07 21:41:03 -04:00
Dashboard.setCurrentUser(user.Id, result.AccessToken);
2013-07-08 12:13:21 -04:00
2013-07-30 21:37:39 -04:00
if (user.Configuration.IsAdministrator) {
2014-07-07 21:41:03 -04:00
window.location = "dashboard.html?u=" + user.Id + '&t=' + result.AccessToken;
2013-07-30 21:37:39 -04:00
} else {
2014-07-07 21:41:03 -04:00
window.location = "index.html?u=" + user.Id + '&t=' + result.AccessToken;
2013-07-30 21:37:39 -04:00
}
}).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 = "";
2014-07-07 21:41:03 -04:00
var page = $.mobile.activePage;
2013-02-20 20:33:05 -05:00
for (var i = 0, length = users.length; i < length; i++) {
var user = users[i];
html += '<div class="card squareCard alternateHover bottomPaddedCard"><div class="cardBox visualCardBox">';
2013-02-20 20:33:05 -05:00
2014-07-26 13:30:15 -04:00
html += '<div class="cardScalable">';
html += '<div class="cardPadder"></div>';
html += '<a class="cardContent" href="#" data-ajax="false" data-haspw="' + user.HasPassword + '" data-username="' + user.Name + '" data-userid="' + user.Id + '">';
2013-02-20 20:33:05 -05:00
2014-07-29 23:31:35 -04:00
var imgUrl;
2013-02-20 20:33:05 -05:00
if (user.PrimaryImageTag) {
imgUrl = ApiClient.getUserImageUrl(user.Id, {
2014-07-26 13:30:15 -04:00
width: 300,
tag: user.PrimaryImageTag,
type: "Primary"
2013-02-20 20:33:05 -05:00
});
2014-07-26 13:30:15 -04:00
html += '<div class="cardImage" style="background-image:url(\'' + imgUrl + '\');"></div>';
2013-04-25 19:28:01 -04:00
}
else {
var background = LibraryBrowser.getMetroColor(user.Id);
2014-07-29 23:31:35 -04:00
imgUrl = 'css/images/logindefault.png';
html += '<div class="cardImage" style="background-image:url(\'' + imgUrl + '\');background-color:' + background + ';"></div>';
2013-02-20 20:33:05 -05:00
}
2014-07-26 13:30:15 -04:00
html += '</a>';
html += '</div>';
html += '<div class="cardFooter">';
html += '<div class="cardText">' + user.Name + '</div>';
2013-04-25 19:28:01 -04:00
2014-07-26 13:30:15 -04:00
html += '<div class="cardText">';
var lastSeen = LoginPage.getLastSeenText(user.LastActivityDate);
if (lastSeen != "") {
html += lastSeen;
}
else {
html += "&nbsp;";
}
2013-02-20 20:33:05 -05:00
html += '</div>';
2014-07-26 13:30:15 -04:00
html += '</div>';
html += '</div>';
2013-02-20 20:33:05 -05:00
2014-07-26 13:30:15 -04:00
html += '</div>';
2013-02-20 20:33:05 -05:00
}
2014-07-07 21:41:03 -04:00
var elem = $('#divUsers', '#loginPage').html(html);
2014-07-26 13:30:15 -04:00
$('a', elem).on('click', function () {
2014-07-07 21:41:03 -04:00
var name = this.getAttribute('data-username');
var haspw = this.getAttribute('data-haspw');
2013-02-20 20:33:05 -05:00
if (haspw == 'false') {
2014-07-07 21:41:03 -04:00
LoginPage.authenticateUserByName(name, '');
} else {
$('#txtManualName', page).val(name);
$('#txtManualPassword', '#loginPage').val('');
LoginPage.showManualForm(page, true);
}
});
2013-02-20 20:33:05 -05:00
},
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;
}
};
2014-07-14 21:25:58 -04:00
$(document).on('pageshow', "#loginPage", LoginPage.onPageShow);