Edit UserRoles over the webserver

This commit is contained in:
lukeIam committed 2013-12-13 17:43:17 +01:00
1 parent 652fdabc3e
commit 08f4428e28
3 files changed
+136 -4

No files matched your search

@@ -119,6 +119,22 @@ namespace ServerLib
SongInfo[] getAllSongs();
#endregion
#region user management
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getUserRole?profileId={profileId}")]
int getUserRole(int profileId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")]
void setUserRole(int profileId, int userRole);
#endregion
}
class CWebservice : ICWebservice
@@ -386,5 +402,25 @@ namespace ServerLib
}
#endregion
#region user management
public int getUserRole(int profileId)
{
return CServer.GetUserRole(profileId);
}
public void setUserRole(int profileId, int userRole)
{
Guid sessionKey = getSession();
if (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles))
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
return;
}
CServer.SetUserRole(profileId, userRole);
}
#endregion
}
}
+35 -2
View File
@@ -83,10 +83,10 @@
</a>
</li>
<li>
<a href="#" data-transition="slidefade">
<a href="#selectUserAdmin" data-transition="slidefade">
<img src="img/admin.png">
<h2>Administration</h2>
<p>Configure options and rights</p>
<p>Configure user rights</p>
</a>
</li>
</ul>
@@ -231,6 +231,39 @@
</div>
<!-- /page -->
<div id="selectUserAdmin" data-content-theme="a" data-role="page" data-add-back-btn="true">
<div data-role="header">
<h1>All profiles</h1>
</div>
<!-- /header -->
<div id="selectUserAdminContent" data-role="content">
<ul id="selectUserAdminList" data-role="listview"></ul>
</div>
<!-- /content -->
</div>
<!-- /page -->
<div id="displayUserAdmin" data-content-theme="a" data-role="page" data-add-back-btn="true">
<div data-role="header">
<h1>Profile</h1>
</div>
<!-- /header -->
<div id="displayUserAdminContent" data-role="content">
<fieldset data-role="controlgroup">
<legend></legend>
<input type="checkbox" id="roleAuthenticatedUser" checked="checked" disabled="disabled">
<label for="roleAuthenticatedUser">AuthenticatedUser</label>
<input type="checkbox" id="roleAdministrator">
<label for="roleAdministrator">Administrator</label>
</fieldset>
<a data-role="button" id="btnRoleSave" data-transition="slidefade">Save</a>
</div>
<!-- /content -->
</div>
<!-- /page -->
<div class="ui-loader-background"></div>
</body>
</html>
+65 -2
View File
@@ -59,7 +59,7 @@ function initPageLoadHandler() {
$.mobile.loading('show', {
text: 'Uploading profile...',
textVisible: true
});
});
$.ajax({
url: "sendProfile",
@@ -69,7 +69,7 @@ function initPageLoadHandler() {
headers: { "session": sessionId },
data: JSON.stringify(dataToUpload),
success: function (msg) {
history.back();
}
}).always(function () {
$.mobile.loading('hide');
@@ -298,6 +298,67 @@ function initPageLoadHandler() {
handleGetAllSongs()
}
});
//pageLoadHandler for selectUserAdmin
$(document).on('pagebeforeshow', '#selectUserAdmin', function () {
var promise = $.ajax({
url: "getProfileList",
headers: { "session": sessionId }
}).done(function (data) {
$('#selectUserAdminList').children().remove();
function handleSelectUserAdminLineClick(e) {
profileIdRequest = parseInt(e.currentTarget.id.replace("SelectUserAdminLine_", ""));
$.mobile.changePage("#displayUserAdmin", { transition: "slidefade" });
}
for (var profile in data) {
$('<li id="SelectUserAdminLine_' + data[profile].ProfileId + '"> <a href="#"> <img src="' + ((data[profile].Avatar && data[profile].Avatar.base64Data) ? data[profile].Avatar.base64Data : "img/profile.png") + '"> <h2>' + data[profile].PlayerName + '</h2> <p>Click here to edit roles for ' + data[profile].PlayerName + '</p> </a> </li>')
.appendTo('#selectUserAdminList')
.click(handleSelectUserAdminLineClick);
}
$('#selectUserAdminList').listview('refresh');
});
// Save promise on page so the transition handler can find it.
$(this).data('promise', promise);
});
//pageLoadHandler for displayUserAdmin
$(document).on('pagebeforeshow', '#displayUserAdmin', function () {
var promise = $.ajax({
url: "getUserRole?profileId=" + profileIdRequest,
headers: { "session": sessionId }
}).done(function (result) {
$('#roleAdministrator').prop("checked", ((result & 0x01) != 0)).checkboxradio("refresh");
$('#btnRoleSave').unbind('click').click(function () {
$('#content').wrap('<div class="overlay" />');
$.mobile.loading('show', {
text: 'Save...',
textVisible: true
});
var role = 0;
if ($('#roleAdministrator').prop("checked")) {
role = (role | 0x01);
}
$.ajax({
url: "setUserRole?profileId=" + profileIdRequest + "&userRole=" + role,
headers: { "session": sessionId }
}).done(function (result) {
$.mobile.loading('hide');
$('#content').unwrap();
history.back();
});
});
});
// Save promise on page so the transition handler can find it.
$(this).data('promise', promise);
});
}
function initLoginPageHandler() {
@@ -419,6 +480,8 @@ function initMainPageHandler() {
$('#capture').click();
});
}
function initKeyboardPageHandler() {