added some user access settings

This commit is contained in:
Luke Pulverenti 2013-07-08 12:13:21 -04:00
parent 1663b40737
commit a2ce0bdce6
10 changed files with 252 additions and 19 deletions

View File

@ -1432,9 +1432,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
/**
* Gets all users from the server
*/
self.getUsers = function () {
self.getUsers = function (options) {
var url = self.getUrl("users");
var url = self.getUrl("users", options || {});
return self.ajax({
type: "GET",
@ -1870,6 +1870,32 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return files;
};
/**
* Authenticates a user
* @param {String} name
* @param {String} password
*/
self.authenticateUserByName = function (name, password) {
if (!name) {
throw new Error("null name");
}
var url = self.getUrl("Users/" + name + "/authenticatebyname");
var postData = {
password: MediaBrowser.SHA1(password || "")
};
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(postData),
dataType: "json",
contentType: "application/json"
});
};
/**
* Authenticates a user
* @param {String} userId
@ -1891,6 +1917,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
type: "POST",
url: url,
data: JSON.stringify(postData),
dataType: "json",
contentType: "application/json"
});
};

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<title>User Profiles</title>
</head>
<body>
<div id="allUserSettingsPage" data-role="page" class="page type-interior userProfilesConfigurationPage">
<div data-role="content">
<div class="content-primary">
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true">
<a href="userprofiles.html" data-role="button">Users</a>
<a href="allusersettings.html" class="ui-btn-active" data-role="button">Settings</a>
</div>
<form id="allUserSettingsForm">
<p>Require manual username entry for:</p>
<div data-role="controlgroup">
<input type="checkbox" data-mini="true" id="chkMobileClients" name="chkMobileClients" />
<label for="chkMobileClients">Mobile Clients</label>
<input type="checkbox" data-mini="true" id="chkMBT" name="chkMBT" />
<label for="chkMBT">Media Browser Theater</label>
</div>
<div class="fieldDescription">This will be ignored on localhost</div>
<br />
<br />
<ul data-role="listview" class="ulForm">
<li>
<button type="submit" data-theme="b" data-icon="ok">
Save
</button>
<button type="button" onclick="Dashboard.navigate('dashboard.html');" data-icon="delete">
Cancel
</button>
</li>
</ul>
</form>
</div>
</div>
<script type="text/javascript">
$('#allUserSettingsForm').on('submit', AllUserSettingsPage.onSubmit);
</script>
</div>
</body>
</html>

View File

@ -68,7 +68,7 @@
<input type="hidden" name="return" id="paypalReturnUrl" value="#">
<a data-role="button" onclick="_xclick.submit();">
<img src="css/images/supporter/donatepaypal.png" /></a>
<a href="https://github.com/MediaBrowser" data-role="button" target="_blank">Become a Developer</a>
<a href="https://github.com/MediaBrowser/MediaBrowser/wiki" data-role="button" target="_blank">Become a Developer</a>
</form>
</div>
</div>

View File

@ -12,7 +12,7 @@
<a href="#" data-role="button" class="ui-btn-active">Profile</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('userimage.html', true);">Image</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('updatepassword.html', true);">Password</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('library.html', true);" class="lnkMediaLibrary" style="display:none;">Media Library</a>
<a href="#" data-role="button" onclick="Dashboard.navigate('library.html', true);" class="lnkMediaLibrary" style="display: none;">Media Library</a>
</div>
<form id="editUserProfileForm">
<ul data-role="listview" class="ulForm">
@ -25,14 +25,28 @@
<label for="chkIsAdmin">Allow this user to manage the server</label>
</li>
</ul>
<div id="accessControlDiv" style="display: none">
<h2>Access Control</h2>
<ul data-role="listview" class="ulForm">
<li id="fldIsEnabled">
<input type="checkbox" id="chkDisabled" name="chkDisabled" />
<label for="chkDisabled">Disable this user</label>
<div class="fieldDescription">If disabled the server will not allow any connections from this user. Existing connections will be abruptly terminated.</div>
</li>
<li id="fldIsHidden">
<input type="checkbox" id="chkIsHidden" name="chkIsHidden" />
<label for="chkIsHidden">Hide this user from login screens</label>
</li>
</ul>
</div>
<div id="parentalControlDiv" style="display: none">
<h2>Parental Control</h2>
<ul data-role="listview" class="ulForm">
<li id="fldMaxParentalRating" >
<li id="fldMaxParentalRating">
<label for="selectMaxParentalRating">Max parental rating:</label>
<select name="selectMaxParentalRating" id="selectMaxParentalRating"></select>
</li>
<li id="fldBlockNotRated" >
<li id="fldBlockNotRated">
<input type="checkbox" id="chkBlockNotRated" name="chkBlockNotRated" />
<label for="chkBlockNotRated">Block items with no rating information</label>
</li>
@ -69,4 +83,4 @@
</script>
</div>
</body>
</html>
</html>

View File

@ -7,11 +7,28 @@
<div id="loginPage" data-role="page" class="page standalonePage">
<div data-role="content">
<div id="divUsers" style="margin: 50px 0 20px; text-align: center;"></div>
<form id="manualLoginForm" style="display: none; text-align: center; margin: 0 auto;">
<h2 style="text-align: left;">Please sign in</h2>
<label for="txtManualName" style="text-align: left;">User:</label>
<input type="text" name="txtManualName" id="txtManualName" />
<label for="txtManualPassword" style="text-align: left;">Password:</label>
<input type="password" name="txtManualPassword" id="txtManualPassword" placeholder="password" />
<p>
<button type="submit" data-theme="b" data-icon="ok">
Sign in
</button>
</p>
</form>
<div id="divUsers" style="display: none; margin: 50px 0 20px; text-align: center;"></div>
</div>
<div data-role="popup" id="popupLogin" class="ui-corner-all popup">
<form id="loginForm">
<form class="loginForm">
<div class="ui-corner-top ui-bar-a" style="text-align: center;">
<h3>Please sign in</h3>
</div>
@ -33,6 +50,7 @@
<script type="text/javascript">
$('#loginForm').on('submit', LoginPage.onSubmit);
$('#manualLoginForm').on('submit', LoginPage.onManualSubmit);
</script>
</div>
</body>

View File

@ -0,0 +1,68 @@
(function ($, document, window) {
function loadPage(page, config) {
var clients = config.ManualLoginClients;
$('#chkMobileClients', page).checked(clients.filter(function (i) {
return i == "Mobile";
}).length > 0).checkboxradio("refresh");
$('#chkMBT', page).checked(clients.filter(function (i) {
return i == "MediaBrowserTheater";
}).length > 0).checkboxradio("refresh");
Dashboard.hideLoadingMsg();
}
$(document).on('pageshow', "#allUserSettingsPage", function () {
Dashboard.showLoadingMsg();
var page = this;
ApiClient.getServerConfiguration().done(function (config) {
loadPage(page, config);
});
});
function allUserSettingsPage() {
var self = this;
self.onSubmit = function () {
Dashboard.showLoadingMsg();
var form = this;
ApiClient.getServerConfiguration().done(function (config) {
var clients = [];
if ($('#chkMobileClients', form).checked()) {
clients.push("Mobile");
}
if ($('#chkMBT', form).checked()) {
clients.push("MediaBrowserTheater");
}
config.ManualLoginClients = clients;
ApiClient.updateServerConfiguration(config).done(Dashboard.processServerConfigurationUpdateResult);
});
// Disable default form submission
return false;
};
}
window.AllUserSettingsPage = new allUserSettingsPage();
})(jQuery, document, window);

View File

@ -59,8 +59,10 @@
if (!loggedInUser.Configuration.IsAdministrator) {
$('#parentalControlDiv', page).hide();
$('#fldIsAdmin', page).hide();
$('#accessControlDiv', page).show();
} else {
$('#parentalControlDiv', page).show();
$('#accessControlDiv', page).show();
$('#fldIsAdmin', page).show();
}
@ -102,6 +104,9 @@
$('#chkIsAdmin', page).checked(user.Configuration.IsAdministrator || false).checkboxradio("refresh");
$('#chkBlockNotRated', page).checked(user.Configuration.BlockNotRated || false).checkboxradio("refresh");
$('#chkDisabled', page).checked(user.Configuration.IsDisabled || false).checkboxradio("refresh");
$('#chkIsHidden', page).checked(user.Configuration.IsHidden || false).checkboxradio("refresh");
Dashboard.hideLoadingMsg();
}
@ -132,6 +137,9 @@
user.Configuration.UseForcedSubtitlesOnly = $('#chkForcedSubtitlesOnly', page).checked();
user.Configuration.BlockNotRated = $('#chkBlockNotRated', page).checked();
user.Configuration.IsHidden = $('#chkIsHidden', page).checked();
user.Configuration.IsDisabled = $('#chkDisabled', page).checked();
var userId = getParameterByName("userId");
if (userId) {

View File

@ -3,7 +3,37 @@
onPageShow: function () {
Dashboard.showLoadingMsg();
ApiClient.getUsers().done(LoginPage.loadUserList);
var promise1 = ApiClient.getUsers({ IsHidden: false });
var promise2 = ApiClient.getServerConfiguration();
$.when(promise1, promise2).done(function (response1, response2) {
var users = response1[0];
var config = response2[0];
var showManualForm = config.ManualLoginClients.filter(function (i) {
return i == "Mobile";
}).length || !users.length;
showManualForm &= window.location.toString().toLowerCase().indexOf('localhost') == -1;
if (showManualForm) {
$('#divUsers', '#loginPage').hide();
$('#manualLoginForm', '#loginPage').show();
} else {
$('#divUsers', '#loginPage').show();
$('#manualLoginForm', '#loginPage').hide();
LoginPage.loadUserList(users);
}
Dashboard.hideLoadingMsg();
});
},
getLastSeenText: function (lastActivityDate) {
@ -33,17 +63,20 @@
LoginPage.authenticateUser(link.getAttribute('data-username'), link.getAttribute('data-userid'));
},
authenticateUser: function (username, userId, password) {
authenticateUser: function (username, password) {
Dashboard.showLoadingMsg();
ApiClient.authenticateUser(userId, password).done(function () {
ApiClient.authenticateUserByName(username, password).done(function (result) {
Dashboard.setCurrentUser(userId);
Dashboard.setCurrentUser(result.User.Id);
window.location = "index.html?u=" + userId;
window.location = "index.html?u=" + result.User.Id;
}).fail(function () {
$('#pw', '#loginPage').val('');
Dashboard.hideLoadingMsg();
setTimeout(function () {
@ -61,9 +94,9 @@
var linkId = "lnkUser" + i;
if (user.HasPassword) {
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-userid='" + user.Id + "' data-username='" + user.Name + "' href='#popupLogin' data-rel='popup' onclick='LoginPage.authenticatingLinkId=this.id;' \">";
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-username='" + user.Name + "' href='#popupLogin' data-rel='popup' onclick='LoginPage.authenticatingLinkId=this.id;' \">";
} else {
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-userid='" + user.Id + "' data-username='" + user.Name + "' href='#' onclick='LoginPage.authenticateUserLink(this);' \">";
html += "<a class='posterItem squarePosterItem' id='" + linkId + "' data-username='" + user.Name + "' href='#' onclick='LoginPage.authenticateUserLink(this);' \">";
}
if (user.PrimaryImageTag) {
@ -100,15 +133,23 @@
$('#divUsers', '#loginPage').html(html);
Dashboard.hideLoadingMsg();
},
onSubmit: function () {
$('#popupLogin', '#loginPage').popup('close');
var link = $('#' + LoginPage.authenticatingLinkId)[0];
LoginPage.authenticateUser(link.getAttribute('data-username'), link.getAttribute('data-userid'), $('#pw', '#loginPage').val());
LoginPage.authenticateUser(link.getAttribute('data-username'), $('#pw', '#loginPage').val());
// Disable default form submission
return false;
},
onManualSubmit: function () {
LoginPage.authenticateUser($('#txtManualName', '#loginPage').val(), $('#txtManualPassword', '#loginPage').val());
// Disable default form submission
return false;

View File

@ -8,6 +8,12 @@
<div data-role="content">
<div class="content-primary">
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true">
<a href="userprofiles.html" data-role="button" class="ui-btn-active">Users</a>
<a href="allusersettings.html" data-role="button">Settings</a>
</div>
<div class="readOnlyContent">
<p id="pAddUser">
<button type="button" data-icon="plus" onclick="Dashboard.navigate('edituser.html');">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.135" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.138" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.54" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.54" targetFramework="net45" />
</packages>