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-05-05 19:15:47 -04:00
|
|
|
|
// Show all users on localhost
|
|
|
|
|
var promise1 = apiClient.getPublicUsers();
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
2015-05-05 19:15:47 -04:00
|
|
|
|
promise1.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 {
|
2014-07-03 22:22:57 -04:00
|
|
|
|
|
2015-05-05 19:15:47 -04:00
|
|
|
|
LoginPage.showVisualForm(page);
|
|
|
|
|
LoginPage.loadUserList(page, apiClient, users);
|
|
|
|
|
}
|
2014-07-03 22:22:57 -04:00
|
|
|
|
|
2015-05-05 19:15:47 -04:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
apiClient.getJSON(apiClient.getUrl('Branding/Configuration')).done(function (options) {
|
|
|
|
|
|
|
|
|
|
$('.disclaimer', page).html(options.LoginDisclaimer || '');
|
|
|
|
|
});
|
2014-07-03 22:22:57 -04:00
|
|
|
|
});
|
2015-05-05 19:15:47 -04:00
|
|
|
|
|
|
|
|
|
if (Dashboard.isConnectMode()) {
|
|
|
|
|
$('.connectButtons', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.connectButtons', page).hide();
|
|
|
|
|
}
|
2014-07-03 22:22:57 -04:00
|
|
|
|
},
|
|
|
|
|
|
2014-11-08 22:18:14 -05:00
|
|
|
|
cancelLogin: function () {
|
2014-07-07 21:41:03 -04:00
|
|
|
|
|
|
|
|
|
LoginPage.showVisualForm($.mobile.activePage);
|
|
|
|
|
},
|
|
|
|
|
|
2015-01-26 11:47:15 -05:00
|
|
|
|
showManualForm: function (page, showCancel, focusPassword) {
|
2014-07-03 22:22:57 -04:00
|
|
|
|
$('.visualLoginForm', page).hide();
|
|
|
|
|
$('#manualLoginForm', page).show();
|
2015-01-26 11:47:15 -05:00
|
|
|
|
|
|
|
|
|
if (focusPassword) {
|
|
|
|
|
$('#txtManualPassword', page).focus();
|
|
|
|
|
} else {
|
|
|
|
|
$('#txtManualName', page).focus();
|
|
|
|
|
}
|
2014-11-08 22:18:14 -05:00
|
|
|
|
|
2014-07-07 21:41:03 -04:00
|
|
|
|
if (showCancel) {
|
|
|
|
|
$('.btnCancel', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.btnCancel', page).hide();
|
|
|
|
|
}
|
2014-07-03 22:22:57 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
},
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
|
|
// In a multi-server supported app, set the server address
|
|
|
|
|
if (serverId) {
|
|
|
|
|
Dashboard.serverAddress(apiClient.serverAddress());
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 21:41:03 -04:00
|
|
|
|
Dashboard.setCurrentUser(user.Id, result.AccessToken);
|
2013-07-08 12:13:21 -04:00
|
|
|
|
|
2015-05-05 19:15:47 -04:00
|
|
|
|
if (user.Policy.IsAdministrator && !serverId) {
|
2015-05-16 23:17:23 -04:00
|
|
|
|
window.location.href = "dashboard.html?u=" + user.Id + '&t=' + result.AccessToken;
|
2013-07-30 21:37:39 -04:00
|
|
|
|
} else {
|
2015-05-16 23:17:23 -04:00
|
|
|
|
window.location.href = "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-07-30 21:35:23 -04: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];
|
|
|
|
|
|
2014-08-02 22:16:37 -04:00
|
|
|
|
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,
|
2013-02-22 09:28:35 -06:00
|
|
|
|
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">';
|
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>';
|
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('');
|
2015-01-26 11:47:15 -05:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-14 21:25:58 -04:00
|
|
|
|
$(document).on('pageshow', "#loginPage", LoginPage.onPageShow);
|