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

228 lines
6.4 KiB
JavaScript
Raw Normal View History

2013-02-20 20:33:05 -05:00
var LoginPage = {
2015-05-05 19:15:47 -04:00
getApiClient: function () {
var serverId = getParameterByName('serverid');
var deferred = DeferredBuilder.Deferred();
if (serverId) {
deferred.resolveWith(null, [ConnectionManager.getOrCreateApiClient(serverId)]);
} else {
deferred.resolveWith(null, [ApiClient]);
}
return deferred.promise();
},
2013-02-20 20:33:05 -05:00
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;
2015-05-05 19:15:47 -04:00
LoginPage.getApiClient().done(function (apiClient) {
2013-07-08 12:13:21 -04:00
2015-06-17 11:39:46 -04:00
apiClient.getPublicUsers().done(function (users) {
2013-07-08 12:13:21 -04:00
2015-05-05 19:15:47 -04:00
var showManualForm = !users.length;
2013-07-08 12:13:21 -04:00
2015-05-05 19:15:47 -04:00
if (showManualForm) {
2013-07-08 12:13:21 -04:00
2015-05-05 19:15:47 -04:00
LoginPage.showManualForm(page, false, false);
2013-07-08 12:13:21 -04:00
2015-05-05 19:15:47 -04:00
} else {
2015-05-05 19:15:47 -04:00
LoginPage.showVisualForm(page);
LoginPage.loadUserList(page, apiClient, users);
}
2015-05-05 19:15:47 -04:00
Dashboard.hideLoadingMsg();
});
apiClient.getJSON(apiClient.getUrl('Branding/Configuration')).done(function (options) {
$('.disclaimer', page).html(options.LoginDisclaimer || '');
});
});
2015-05-05 19:15:47 -04:00
if (Dashboard.isConnectMode()) {
$('.connectButtons', page).show();
} else {
$('.connectButtons', page).hide();
}
},
cancelLogin: function () {
2014-07-07 21:41:03 -04:00
LoginPage.showVisualForm($.mobile.activePage);
},
showManualForm: function (page, showCancel, focusPassword) {
$('.visualLoginForm', page).hide();
2015-05-19 15:15:40 -04:00
$('.manualLoginForm', page).show();
if (focusPassword) {
2015-07-28 23:42:03 -04:00
$('#txtManualPassword input', page).focus();
} else {
2015-07-28 23:42:03 -04:00
$('#txtManualName input', 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();
2015-05-19 15:15:40 -04:00
$('.manualLoginForm', page).hide();
2013-02-20 20:33:05 -05:00
},
getLastSeenText: function (lastActivityDate) {
if (!lastActivityDate) {
return "";
}
return "Last seen " + humane_date(lastActivityDate);
},
2015-05-05 19:15:47 -04:00
authenticateUserByName: function (apiClient, username, password) {
2013-07-30 21:37:39 -04:00
Dashboard.showLoadingMsg();
2013-07-15 21:36:18 -04:00
2015-05-05 19:15:47 -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
2015-05-05 19:15:47 -04:00
var serverId = getParameterByName('serverid');
2015-05-17 21:27:48 -04:00
var newUrl;
2013-07-08 12:13:21 -04:00
2015-05-05 19:15:47 -04:00
if (user.Policy.IsAdministrator && !serverId) {
2015-05-20 12:28:55 -04:00
newUrl = "dashboard.html";
2013-07-30 21:37:39 -04:00
} else {
2015-05-20 12:28:55 -04:00
newUrl = "index.html";
2013-07-30 21:37:39 -04:00
}
2015-06-17 11:39:46 -04:00
Dashboard.hideLoadingMsg();
2015-05-20 12:28:55 -04:00
Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient);
2015-05-17 21:27:48 -04:00
Dashboard.navigate(newUrl);
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
},
2015-05-05 19:15:47 -04:00
loadUserList: function (page, apiClient, users) {
2013-02-20 20:33:05 -05:00
var html = "";
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) {
2015-05-05 19:15:47 -04:00
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
2015-05-05 19:15:47 -04:00
var id = this.getAttribute('data-userid');
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
2015-05-05 19:15:47 -04:00
if (id == 'manual') {
LoginPage.showManualForm(page, true);
}
else if (haspw == 'false') {
LoginPage.authenticateUserByName(apiClient, name, '');
2014-07-07 21:41:03 -04:00
} else {
$('#txtManualName', page).val(name);
$('#txtManualPassword', '#loginPage').val('');
LoginPage.showManualForm(page, true, true);
2014-07-07 21:41:03 -04:00
}
});
2013-02-20 20:33:05 -05:00
},
2013-07-08 12:13:21 -04:00
onManualSubmit: function () {
2015-05-05 19:15:47 -04:00
LoginPage.getApiClient().done(function (apiClient) {
LoginPage.authenticateUserByName(apiClient, $('#txtManualName', '#loginPage').val(), $('#txtManualPassword', '#loginPage').val());
});
2013-02-20 20:33:05 -05:00
// Disable default form submission
return false;
}
};
2015-05-19 15:15:40 -04:00
$(document).on('pageinitdepends', "#loginPage", function () {
var page = this;
$('.manualLoginForm', page).off('submit', LoginPage.onManualSubmit).on('submit', LoginPage.onManualSubmit);
2015-06-16 00:52:01 -04:00
$('.btnForgotPassword', page).on('click', function () {
Dashboard.navigate('forgotpassword.html');
});
2015-05-19 15:15:40 -04:00
}).on('pageshowready', "#loginPage", LoginPage.onPageShow);