2013-02-20 20:33:05 -05:00
|
|
|
|
var LoginPage = {
|
|
|
|
|
|
2014-02-23 22:27:13 -05:00
|
|
|
|
onPageInit: function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$("#popupLogin", page).popup({
|
|
|
|
|
afteropen: function (event, ui) {
|
|
|
|
|
$('#pw').focus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
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;
|
|
|
|
|
|
2014-02-21 00:04:11 -05:00
|
|
|
|
var isLocalhost = window.location.toString().toLowerCase().indexOf('localhost') != -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
|
|
|
|
var promise2 = ApiClient.getServerConfiguration();
|
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
|
|
|
|
|
var users = response1[0];
|
|
|
|
|
var config = response2[0];
|
|
|
|
|
|
2014-05-23 19:58:28 -04:00
|
|
|
|
var showManualForm = config.RequireMobileManualLogin || !users.length;
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
|
|
|
|
if (showManualForm) {
|
|
|
|
|
|
2014-02-23 22:27:13 -05:00
|
|
|
|
$('.visualLoginForm', page).hide();
|
|
|
|
|
$('#manualLoginForm', page).show();
|
|
|
|
|
$('#txtManualName', page).focus();
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2014-02-23 22:27:13 -05:00
|
|
|
|
$('.visualLoginForm', page).show();
|
|
|
|
|
$('#manualLoginForm', page).hide();
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
|
|
|
|
LoginPage.loadUserList(users);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
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,
|
2013-02-22 09:28:35 -06:00
|
|
|
|
tag: user.PrimaryImageTag,
|
|
|
|
|
type: "Primary"
|
2013-02-20 20:33:05 -05:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
authenticateUserLink: function (link) {
|
|
|
|
|
|
2013-07-30 21:35:23 -04:00
|
|
|
|
LoginPage.authenticateUser(link.getAttribute('data-userid'));
|
2013-02-20 20:33:05 -05:00
|
|
|
|
},
|
|
|
|
|
|
2013-07-30 21:35:23 -04:00
|
|
|
|
authenticateUser: function (userId, password) {
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2013-07-30 21:35:23 -04:00
|
|
|
|
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 () {
|
|
|
|
|
Dashboard.showError("Invalid user or password.");
|
|
|
|
|
}, 300);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
});
|
2013-07-30 21:35:23 -04:00
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadUserList: function (users) {
|
|
|
|
|
var html = "";
|
|
|
|
|
|
2014-02-08 15:02:35 -05:00
|
|
|
|
var isLocalhost = window.location.toString().toLowerCase().indexOf('localhost') != -1;
|
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
for (var i = 0, length = users.length; i < length; i++) {
|
|
|
|
|
var user = users[i];
|
|
|
|
|
|
|
|
|
|
var linkId = "lnkUser" + i;
|
|
|
|
|
|
2014-02-08 15:02:35 -05:00
|
|
|
|
if (isLocalhost) {
|
|
|
|
|
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-userid='" + user.Id + "' href='index.html?u=" + user.Id + "' data-ajax='false' \">";
|
|
|
|
|
}
|
|
|
|
|
else if (user.HasPassword) {
|
2013-07-30 21:35:23 -04:00
|
|
|
|
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-userid='" + user.Id + "' href='#popupLogin' data-rel='popup' onclick='LoginPage.authenticatingLinkId=this.id;' \">";
|
2013-02-20 20:33:05 -05:00
|
|
|
|
} else {
|
2013-07-30 21:35:23 -04:00
|
|
|
|
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-userid='" + user.Id + "' href='#' onclick='LoginPage.authenticateUserLink(this);' \">";
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.PrimaryImageTag) {
|
|
|
|
|
|
|
|
|
|
var imgUrl = ApiClient.getUserImageUrl(user.Id, {
|
|
|
|
|
width: 500,
|
2013-02-22 09:28:35 -06:00
|
|
|
|
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;">';
|
2013-02-22 09:08:51 -06:00
|
|
|
|
var lastSeen = LoginPage.getLastSeenText(user.LastActivityDate);
|
|
|
|
|
if (lastSeen != "") {
|
|
|
|
|
html += lastSeen;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
html += " ";
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '</a>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#divUsers', '#loginPage').html(html);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onSubmit: function () {
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
$('#popupLogin', '#loginPage').popup('close');
|
|
|
|
|
|
|
|
|
|
var link = $('#' + LoginPage.authenticatingLinkId)[0];
|
|
|
|
|
|
2013-07-30 21:35:23 -04:00
|
|
|
|
LoginPage.authenticateUser(link.getAttribute('data-userid'), $('#pw', '#loginPage').val());
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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-02-23 22:27:13 -05:00
|
|
|
|
$(document).on('pageshow', "#loginPage", LoginPage.onPageShow).on('pageinit', "#loginPage", LoginPage.onPageInit);
|