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

@ -346,7 +346,7 @@ h1 .imageLink {
}
.dashboardPanelLink {
padding: .5em .5em .5em 1.25em;
padding: .6em .5em .6em 1.25em;
display: block;
text-decoration: none;
color: #fff!important;

View File

@ -21,6 +21,12 @@
${ButtonSignIn}
</button>
</p>
<p>
<button type="button" data-icon="delete" onclick="LoginPage.cancelLogin();" class="btnCancel">
${ButtonCancel}
</button>
</p>
</form>
<div class="visualLoginForm" style="display: none; text-align: center;">

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');
});
});
}
};

View File

@ -12,7 +12,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
keys.push((navigator.cpuClass || ""));
var randomId = '';
if (localStorage) {
// Since the above is not guaranteed to be unique per device, add a little more
@ -29,7 +29,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
keys.push(randomId);
return MediaBrowser.SHA1(keys.join('|'));
}
/**
* Creates a new api client instance
* @param {String} serverAddress
@ -46,6 +46,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
var deviceName = "Web Browser";
var deviceId = generateDeviceId();
var currentUserId;
var accessToken;
var webSocket;
/**
@ -59,13 +60,15 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
/**
* Gets or sets the current user id.
*/
self.currentUserId = function (val) {
self.getCurrentUserId = function () {
if (val !== undefined) {
currentUserId = val;
} else {
return currentUserId;
}
return currentUserId;
};
self.setCurrentUserId = function (userId, token) {
currentUserId = userId;
accessToken = token;
};
deviceName = (function () {
@ -144,10 +147,14 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
};
}
if (accessToken) {
request.headers['X-MediaBrowser-Token'] = accessToken;
}
return $.ajax(request);
};
self.getJSON = function(url) {
self.getJSON = function (url) {
return self.ajax({
type: "GET",
@ -349,6 +356,26 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
});
};
self.logout = function () {
var done = function () {
self.setCurrentUserId(null, null);
};
if (accessToken) {
var url = self.getUrl("Sessions/Logout");
return self.ajax({
type: "POST",
url: url
}).done(done);
}
var deferred = $.Deferred();
deferred.resolveWith(null, []);
return deferred.promise().done(done);
};
function getRemoteImagePrefix(options) {
var urlPrefix;
@ -1319,7 +1346,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
dataType: "json"
});
};
self.getNamedConfiguration = function (name) {
var url = self.getUrl("System/Configuration/" + name);
@ -2115,8 +2142,11 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
if (ratio) {
if (options.width) {
if (options.minScale) {
ratio = Math.max(options.minScale, ratio);
}
if (options.width) {
options.width = Math.round(options.width * ratio);
}
if (options.height) {
@ -2129,7 +2159,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
options.maxHeight = Math.round(options.maxHeight * ratio);
}
}
options.quality = options.quality || (options.type.toLowerCase() == 'backdrop' ? 80 : 90);
}
@ -2263,6 +2293,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
// Don't put these on the query string
delete options.type;
delete options.index;
delete options.minScale;
return self.getUrl(url, options);
};
@ -3476,7 +3507,7 @@ MediaBrowser.SHA1 = function (msg) {
} else if (browser.webkit) {
browser.safari = true;
}
browser.mobile = (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
jQuery.browser = browser;