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 { .dashboardPanelLink {
padding: .5em .5em .5em 1.25em; padding: .6em .5em .6em 1.25em;
display: block; display: block;
text-decoration: none; text-decoration: none;
color: #fff!important; color: #fff!important;

View File

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

View File

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

View File

@ -113,11 +113,11 @@
html += '<div style="margin:20px 0 0;">'; html += '<div style="margin:20px 0 0;">';
html += '<label for="txtDirectoryPickerPath" class="lblDirectoryPickerPath">' + Globalize.translate('LabelCurrentPath') + '</label>'; 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 += '<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>';
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>'; 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) { if (item.ImageTags.Primary) {
// Scaling 400w episode images to 80 doesn't turn out very well // 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, { imgUrl = ApiClient.getScaledImageUrl(item.Id, {
width: width, width: 80,
tag: item.ImageTags.Primary, tag: item.ImageTags.Primary,
type: "Primary", type: "Primary",
index: 0 index: 0,
EnableImageEnhancers: false,
minScale: minScale
}); });
} }
@ -649,7 +651,7 @@
if (item.UserData.UnplayedItemCount) { if (item.UserData.UnplayedItemCount) {
html += '<span class="ui-li-count">' + item.UserData.UnplayedItemCount + '</span>'; 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>'; 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>'; return '<div class="playedIndicator">' + item.UserData.UnplayedItemCount + '</div>';
} }
if (item.UserData.PlayedPercentage >= 100 || (item.UserData && item.UserData.Played)) { if (item.Type != 'TvChannel') {
return '<div class="playedIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></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>';
}
} }
} }

View File

@ -6,25 +6,22 @@
var page = this; var page = this;
var location = window.location.toString().toLowerCase(); if (LoginPage.isLocalhost()) {
var isLocalhost = location.indexOf('localhost') != -1 || location.indexOf('127.0.0.1') != -1;
if (isLocalhost) {
$('.localhostMessage', page).show(); $('.localhostMessage', page).show();
} else { } else {
$('.localhostMessage', page).hide(); $('.localhostMessage', page).hide();
} }
// Show all users on localhost // Show all users on localhost
var promise1 = !isLocalhost ? ApiClient.getPublicUsers() : ApiClient.getUsers({ IsDisabled: false }); var promise1 = ApiClient.getPublicUsers();
promise1.done(function (users) { promise1.done(function (users) {
var showManualForm = !users.length || !isLocalhost; var showManualForm = !users.length;
if (showManualForm) { if (showManualForm) {
LoginPage.showManualForm(page); LoginPage.showManualForm(page, false);
} else { } else {
LoginPage.showVisualForm(page); 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(); $('.visualLoginForm', page).hide();
$('#manualLoginForm', page).show(); $('#manualLoginForm', page).show();
$('#txtManualName', page).focus(); $('#txtManualName', page).focus();
if (showCancel) {
$('.btnCancel', page).show();
} else {
$('.btnCancel', page).hide();
}
}, },
showVisualForm: function (page) { 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) { authenticateUserByName: function (username, password) {
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
@ -97,12 +95,12 @@
var user = result.User; var user = result.User;
Dashboard.setCurrentUser(user.Id); Dashboard.setCurrentUser(user.Id, result.AccessToken);
if (user.Configuration.IsAdministrator) { if (user.Configuration.IsAdministrator) {
window.location = "dashboard.html?u=" + user.Id; window.location = "dashboard.html?u=" + user.Id + '&t=' + result.AccessToken;
} else { } else {
window.location = "index.html?u=" + user.Id; window.location = "index.html?u=" + user.Id + '&t=' + result.AccessToken;
} }
}).fail(function () { }).fail(function () {
@ -123,12 +121,14 @@
loadUserList: function (users) { loadUserList: function (users) {
var html = ""; var html = "";
var page = $.mobile.activePage;
for (var i = 0, length = users.length; i < length; i++) { for (var i = 0, length = users.length; i < length; i++) {
var user = users[i]; var user = users[i];
var linkId = "lnkUser" + 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) { if (user.PrimaryImageTag) {
@ -162,8 +162,21 @@
html += '</a>'; 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 () { onManualSubmit: function () {

View File

@ -68,6 +68,11 @@ var Dashboard = {
} }
}, },
getAccessToken: function () {
return localStorage.getItem('token');
},
getCurrentUserId: function () { getCurrentUserId: function () {
if (!window.localStorage) { if (!window.localStorage) {
@ -76,24 +81,24 @@ var Dashboard = {
var autoLoginUserId = getParameterByName('u'); var autoLoginUserId = getParameterByName('u');
var storedUserId = localStorage.getItem("userId"); var storedUserId = localStorage.getItem("userId");
var userId;
if (autoLoginUserId && autoLoginUserId != storedUserId) { if (autoLoginUserId && autoLoginUserId != storedUserId) {
localStorage.setItem("userId", autoLoginUserId); var token = getParameterByName('t');
ApiClient.currentUserId(autoLoginUserId); Dashboard.setCurrentUser(autoLoginUserId, token);
} }
return autoLoginUserId || storedUserId; return autoLoginUserId || storedUserId;
}, },
setCurrentUser: function (userId) { setCurrentUser: function (userId, token) {
if (window.localStorage) { if (window.localStorage) {
localStorage.setItem("userId", userId); localStorage.setItem("userId", userId);
localStorage.setItem("token", token);
} }
ApiClient.currentUserId(userId); ApiClient.setCurrentUserId(userId, token);
Dashboard.getUserPromise = null; Dashboard.getUserPromise = null;
}, },
@ -101,11 +106,12 @@ var Dashboard = {
if (window.localStorage) { if (window.localStorage) {
localStorage.removeItem("userId"); localStorage.removeItem("userId");
localStorage.removeItem("token");
} }
Dashboard.getUserPromise = null; ApiClient.logout().done(function () {
ApiClient.currentUserId(null); window.location = "login.html";
window.location = "login.html"; });
}, },
showError: function (message) { showError: function (message) {
@ -146,6 +152,7 @@ var Dashboard = {
updateSystemInfo: function (info) { updateSystemInfo: function (info) {
Dashboard.lastSystemInfo = info; Dashboard.lastSystemInfo = info;
Dashboard.ensureWebSocket(info); Dashboard.ensureWebSocket(info);
if (!Dashboard.initialServerVersion) { if (!Dashboard.initialServerVersion) {
@ -403,10 +410,14 @@ var Dashboard = {
}, },
refreshSystemInfoFromServer: function () { 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 () { restartServer: function () {
@ -649,6 +660,10 @@ var Dashboard = {
name: "Dashboard", name: "Dashboard",
href: "dashboard.html", href: "dashboard.html",
selected: page.hasClass("dashboardHomePage") selected: page.hasClass("dashboardHomePage")
}, {
name: "Users",
href: "userprofiles.html",
selected: page.hasClass("userProfilesConfigurationPage") || (pageElem.id == "mediaLibraryPage" && getParameterByName('userId'))
}, { }, {
name: "Library", name: "Library",
divider: true, divider: true,
@ -679,11 +694,6 @@ var Dashboard = {
name: "Plugins", name: "Plugins",
href: "plugins.html", href: "plugins.html",
selected: page.hasClass("pluginConfigurationPage") selected: page.hasClass("pluginConfigurationPage")
}, {
name: "Users",
divider: true,
href: "userprofiles.html",
selected: page.hasClass("userProfilesConfigurationPage") || (pageElem.id == "mediaLibraryPage" && getParameterByName('userId'))
}, { }, {
name: "Advanced", name: "Advanced",
divider: true, divider: true,
@ -1202,7 +1212,7 @@ var Dashboard = {
$(ApiClient).on("websocketopen", Dashboard.onWebSocketOpened) $(ApiClient).on("websocketopen", Dashboard.onWebSocketOpened)
.on("websocketmessage", Dashboard.onWebSocketMessageReceived); .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(); Dashboard.jQueryMobileInit();
$(document).on('pagebeforeshow', ".page", function () { $(document).on('pagebeforeshow', ".page", function () {

View File

@ -5,25 +5,11 @@
ApiClient.getServerConfiguration().done(function (config) { ApiClient.getServerConfiguration().done(function (config) {
config.IsStartupWizardCompleted = true; config.IsStartupWizardCompleted = true;
ApiClient.updateServerConfiguration(config).done(function () { ApiClient.updateServerConfiguration(config).done(function () {
ApiClient.getUsers().done(function (users) { Dashboard.navigate('dashboard.html');
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');
});
}); });
}); });
} }
}; };

View File

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