completed auth database

This commit is contained in:
Luke Pulverenti 2014-07-07 21:41:03 -04:00
parent 3719b9ad8e
commit 10414ce9ac
9 changed files with 135 additions and 101 deletions

View file

@ -101,7 +101,7 @@
var date = parseISO8601Date(item.Date, { toLocal: true });
itemHtml += '<div class="newsItemDate">' + date.toLocaleDateString() + '</div>';
itemHtml += '<div class="newsItemDescription">' + item.DescriptionHtml + '</div>';
itemHtml += '<div class="newsItemDescription">' + item.Description + '</div>';
itemHtml += '</div>';
return itemHtml;

View file

@ -113,11 +113,11 @@
html += '<div style="margin:20px 0 0;">';
html += '<label for="txtDirectoryPickerPath" class="lblDirectoryPickerPath">' + Globalize.translate('LabelCurrentPath') + '</label>';
html += '<div style="width:92%;display:inline-block;"><input id="txtDirectoryPickerPath" name="txtDirectoryPickerPath" type="text" required="required" style="font-weight:bold;" /></div>';
html += '<div style="width:82%;display:inline-block;"><input id="txtDirectoryPickerPath" name="txtDirectoryPickerPath" type="text" required="required" style="font-weight:bold;" /></div>';
html += '<button class="btnRefreshDirectories" type="button" data-icon="refresh" data-inline="true" data-mini="true" data-iconpos="notext">' + Globalize.translate('ButtonRefresh') + '</button>';
html += '</div>';
html += '<div style="height: 320px; overflow-y: auto;">';
html += '<div style="height: 180px; overflow-y: auto;">';
html += '<ul id="ulDirectoryPickerList" data-role="listview" data-inset="true" data-auto-enhanced="false"></ul>';

View file

@ -595,13 +595,15 @@
if (item.ImageTags.Primary) {
// Scaling 400w episode images to 80 doesn't turn out very well
var width = item.Type == 'Episode' || item.Type == 'Game' ? 160 : 80;
var minScale = item.Type == 'Episode' || item.Type == 'Game' ? 2 : null;
imgUrl = ApiClient.getScaledImageUrl(item.Id, {
width: width,
width: 80,
tag: item.ImageTags.Primary,
type: "Primary",
index: 0
index: 0,
EnableImageEnhancers: false,
minScale: minScale
});
}
@ -649,7 +651,7 @@
if (item.UserData.UnplayedItemCount) {
html += '<span class="ui-li-count">' + item.UserData.UnplayedItemCount + '</span>';
}
else if (item.UserData.Played) {
else if (item.UserData.Played && item.Type != 'TvChannel') {
html += '<div class="playedIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
}
}
@ -1306,8 +1308,10 @@
return '<div class="playedIndicator">' + item.UserData.UnplayedItemCount + '</div>';
}
if (item.UserData.PlayedPercentage >= 100 || (item.UserData && item.UserData.Played)) {
return '<div class="playedIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
if (item.Type != 'TvChannel') {
if (item.UserData.PlayedPercentage >= 100 || (item.UserData && item.UserData.Played)) {
return '<div class="playedIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
}
}
}

View file

@ -6,25 +6,22 @@
var page = this;
var location = window.location.toString().toLowerCase();
var isLocalhost = location.indexOf('localhost') != -1 || location.indexOf('127.0.0.1') != -1;
if (isLocalhost) {
if (LoginPage.isLocalhost()) {
$('.localhostMessage', page).show();
} else {
$('.localhostMessage', page).hide();
}
// Show all users on localhost
var promise1 = !isLocalhost ? ApiClient.getPublicUsers() : ApiClient.getUsers({ IsDisabled: false });
var promise1 = ApiClient.getPublicUsers();
promise1.done(function (users) {
var showManualForm = !users.length || !isLocalhost;
var showManualForm = !users.length;
if (showManualForm) {
LoginPage.showManualForm(page);
LoginPage.showManualForm(page, false);
} else {
LoginPage.showVisualForm(page);
@ -40,10 +37,27 @@
});
},
showManualForm: function (page) {
isLocalhost: function () {
var location = window.location.toString().toLowerCase();
return location.indexOf('localhost') != -1 || location.indexOf('127.0.0.1') != -1;
},
cancelLogin: function() {
LoginPage.showVisualForm($.mobile.activePage);
},
showManualForm: function (page, showCancel) {
$('.visualLoginForm', page).hide();
$('#manualLoginForm', page).show();
$('#txtManualName', page).focus();
if (showCancel) {
$('.btnCancel', page).show();
} else {
$('.btnCancel', page).hide();
}
},
showVisualForm: function (page) {
@ -73,22 +87,6 @@
});
},
authenticateUserLink: function (link) {
LoginPage.authenticateUser(link.getAttribute('data-userid'));
},
authenticateUser: function (userId, password) {
Dashboard.showLoadingMsg();
ApiClient.getUser(userId).done(function (user) {
LoginPage.authenticateUserByName(user.Name, password);
});
},
authenticateUserByName: function (username, password) {
Dashboard.showLoadingMsg();
@ -97,12 +95,12 @@
var user = result.User;
Dashboard.setCurrentUser(user.Id);
Dashboard.setCurrentUser(user.Id, result.AccessToken);
if (user.Configuration.IsAdministrator) {
window.location = "dashboard.html?u=" + user.Id;
window.location = "dashboard.html?u=" + user.Id + '&t=' + result.AccessToken;
} else {
window.location = "index.html?u=" + user.Id;
window.location = "index.html?u=" + user.Id + '&t=' + result.AccessToken;
}
}).fail(function () {
@ -123,12 +121,14 @@
loadUserList: function (users) {
var html = "";
var page = $.mobile.activePage;
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' \">";
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-haspw='" + user.HasPassword + "' data-username='" + user.Name + "' data-userid='" + user.Id + "' href='#' data-ajax='false' \">";
if (user.PrimaryImageTag) {
@ -162,8 +162,21 @@
html += '</a>';
}
$('#divUsers', '#loginPage').html(html);
var elem = $('#divUsers', '#loginPage').html(html);
$('.posterItem', elem).on('click', function () {
var name = this.getAttribute('data-username');
var haspw = this.getAttribute('data-haspw');
if (LoginPage.isLocalhost() || haspw == 'false') {
LoginPage.authenticateUserByName(name, '');
} else {
$('#txtManualName', page).val(name);
$('#txtManualPassword', '#loginPage').val('');
LoginPage.showManualForm(page, true);
}
});
},
onManualSubmit: function () {

View file

@ -68,6 +68,11 @@ var Dashboard = {
}
},
getAccessToken: function () {
return localStorage.getItem('token');
},
getCurrentUserId: function () {
if (!window.localStorage) {
@ -76,24 +81,24 @@ var Dashboard = {
var autoLoginUserId = getParameterByName('u');
var storedUserId = localStorage.getItem("userId");
var userId;
if (autoLoginUserId && autoLoginUserId != storedUserId) {
localStorage.setItem("userId", autoLoginUserId);
ApiClient.currentUserId(autoLoginUserId);
var token = getParameterByName('t');
Dashboard.setCurrentUser(autoLoginUserId, token);
}
return autoLoginUserId || storedUserId;
},
setCurrentUser: function (userId) {
setCurrentUser: function (userId, token) {
if (window.localStorage) {
localStorage.setItem("userId", userId);
localStorage.setItem("token", token);
}
ApiClient.currentUserId(userId);
ApiClient.setCurrentUserId(userId, token);
Dashboard.getUserPromise = null;
},
@ -101,11 +106,12 @@ var Dashboard = {
if (window.localStorage) {
localStorage.removeItem("userId");
localStorage.removeItem("token");
}
Dashboard.getUserPromise = null;
ApiClient.currentUserId(null);
window.location = "login.html";
ApiClient.logout().done(function () {
window.location = "login.html";
});
},
showError: function (message) {
@ -146,6 +152,7 @@ var Dashboard = {
updateSystemInfo: function (info) {
Dashboard.lastSystemInfo = info;
Dashboard.ensureWebSocket(info);
if (!Dashboard.initialServerVersion) {
@ -403,10 +410,14 @@ var Dashboard = {
},
refreshSystemInfoFromServer: function () {
ApiClient.getSystemInfo().done(function (info) {
Dashboard.updateSystemInfo(info);
});
// TODO: Eventually remove the currentUserId check
if (Dashboard.getAccessToken() || Dashboard.getCurrentUserId()) {
ApiClient.getSystemInfo().done(function (info) {
Dashboard.updateSystemInfo(info);
});
}
},
restartServer: function () {
@ -649,6 +660,10 @@ var Dashboard = {
name: "Dashboard",
href: "dashboard.html",
selected: page.hasClass("dashboardHomePage")
}, {
name: "Users",
href: "userprofiles.html",
selected: page.hasClass("userProfilesConfigurationPage") || (pageElem.id == "mediaLibraryPage" && getParameterByName('userId'))
}, {
name: "Library",
divider: true,
@ -679,11 +694,6 @@ var Dashboard = {
name: "Plugins",
href: "plugins.html",
selected: page.hasClass("pluginConfigurationPage")
}, {
name: "Users",
divider: true,
href: "userprofiles.html",
selected: page.hasClass("userProfilesConfigurationPage") || (pageElem.id == "mediaLibraryPage" && getParameterByName('userId'))
}, {
name: "Advanced",
divider: true,
@ -1202,7 +1212,7 @@ var Dashboard = {
$(ApiClient).on("websocketopen", Dashboard.onWebSocketOpened)
.on("websocketmessage", Dashboard.onWebSocketMessageReceived);
ApiClient.currentUserId(Dashboard.getCurrentUserId());
ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken());
})();
@ -1300,22 +1310,6 @@ $(function () {
});
});
$.fn.openPopup = function () {
this.one('popupbeforeposition', function () {
//$("body").on("touchmove.popup", false);
//$('body').addClass('bodyWithPopupOpen');
}).one('popupafterclose', function () {
//$("body").off("touchmove.popup");
//$('body').removeClass('bodyWithPopupOpen');
});
return this.popup('open');
};
Dashboard.jQueryMobileInit();
$(document).on('pagebeforeshow', ".page", function () {

View file

@ -5,25 +5,11 @@
ApiClient.getServerConfiguration().done(function (config) {
config.IsStartupWizardCompleted = true;
ApiClient.updateServerConfiguration(config).done(function () {
ApiClient.getUsers().done(function (users) {
for (var i = 0, length = users.length; i < length; i++) {
if (users[i].Configuration.IsAdministrator) {
Dashboard.setCurrentUser(users[i].Id);
break;
}
}
Dashboard.navigate('dashboard.html');
});
Dashboard.navigate('dashboard.html');
});
});
}
};