Fixed ProfileAccess over webserver
This commit is contained in:
1 parent
c29ae91379
commit
eca41bab2f
4 files changed
+139
-61
No files matched your search
@@ -181,11 +181,14 @@ namespace ServerLib
|
||||
{
|
||||
Guid sessionKey = getSession();
|
||||
|
||||
if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
|
||||
SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId))
|
||||
if (profile.ProfileId != -1) //-1 is the id for a new profile
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
return false;
|
||||
if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
|
||||
SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId))
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (CServer.SendProfileData == null)
|
||||
|
||||
@@ -197,7 +197,12 @@ namespace Vocaluxe.Base.Server
|
||||
}
|
||||
else if (newProfile.Avatar == null)
|
||||
{
|
||||
//TODO:standardAvatar
|
||||
newProfile.Avatar = CProfiles.GetAvatars().First();
|
||||
|
||||
/*CAvatar avatar = new CAvatar(-1);
|
||||
avatar.LoadFromFile("Profiles\\Avatar_f.png");
|
||||
CProfiles.AddAvatar(avatar);
|
||||
newProfile.Avatar = avatar;*/
|
||||
}
|
||||
|
||||
if (profile.PlayerName != null && profile.PlayerName != "")
|
||||
@@ -214,6 +219,11 @@ namespace Vocaluxe.Base.Server
|
||||
newProfile.Difficulty = (EGameDifficulty)profile.Difficulty;
|
||||
}
|
||||
|
||||
if (profile.Type >= 0 && profile.Type <= 1)
|
||||
{
|
||||
newProfile.GuestProfile = (EOffOn)profile.Type;
|
||||
}
|
||||
|
||||
if (existingProfile != null)
|
||||
{
|
||||
CProfiles.EditProfile(newProfile);
|
||||
@@ -412,7 +422,7 @@ namespace Vocaluxe.Base.Server
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
byte[] salt = profile.PasswordSalt;
|
||||
@@ -476,7 +486,7 @@ namespace Vocaluxe.Base.Server
|
||||
if (profile == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid profileId");
|
||||
}
|
||||
}
|
||||
|
||||
profile.UserRoles = userRole;
|
||||
}
|
||||
@@ -484,8 +494,8 @@ namespace Vocaluxe.Base.Server
|
||||
private static int getUserIdFromUsername(string username)
|
||||
{
|
||||
var playerIds = (from p in CProfiles.GetProfiles()
|
||||
where String.Equals(p.PlayerName, username,StringComparison.OrdinalIgnoreCase)
|
||||
select p.ID);
|
||||
where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase)
|
||||
select p.ID);
|
||||
if (playerIds.Count() == 0)
|
||||
{
|
||||
throw new ArgumentException("Invalid playername");
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
<input type="text" id="loginPassword" name="loginPassword" data-mini="true">
|
||||
<br />
|
||||
<a data-role="button" id="loginButton">Login</a>
|
||||
<br />
|
||||
<hr />
|
||||
<br />
|
||||
<a data-role="button" id="registerButton">Create Profile</a>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
</div>
|
||||
|
||||
+113
-52
@@ -38,45 +38,12 @@ function replaceTransitionHandler() {
|
||||
function initPageLoadHandler() {
|
||||
//pageLoadHandler for displayProfile
|
||||
$(document).on('pagebeforeshow', '#displayProfile', function () {
|
||||
var promise = $.ajax({
|
||||
url: "getProfile?profileId=" + profileIdRequest,
|
||||
headers: { "session": sessionId }
|
||||
}).done(function (result) {
|
||||
$('#playerName').prop("value", result.PlayerName);
|
||||
if (result.Avatar && result.Avatar.base64Data) {
|
||||
$('#playerAvatar').prop("src", result.Avatar.base64Data);
|
||||
}
|
||||
$('#playerType').prop("value", result.Type);
|
||||
$('#playerDifficulty').prop("value", result.Difficulty);
|
||||
if (result.IsEditable) {
|
||||
$('#playerName').prop('disabled', false);
|
||||
$('#playerType').prop('disabled', false);
|
||||
$('#playerDifficulty').prop('disabled', false);
|
||||
$('#playerSaveButton').show();
|
||||
|
||||
$('#playerAvatar').unbind("click");
|
||||
$('#playerAvatar').click(function () {
|
||||
if ($('#captureContainer').length > 0) {
|
||||
$('#captureContainer').remove();
|
||||
}
|
||||
|
||||
$(document.body).append('<div id="captureContainer" style="height: 0px;width:0px; overflow:hidden;"> <input type="file" accept="image/*" id="capture" capture> </div>');
|
||||
|
||||
$('#capture').change(function (eventData) {
|
||||
if (eventData && eventData.target && eventData.target.files && eventData.target.files.length == 1) {
|
||||
var file = eventData.target.files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onloadend = function (e) {
|
||||
$('#playerAvatar').prop("src", e.target.result);
|
||||
$('#playerAvatar').data("changed", true);
|
||||
$('#captureContainer').remove();
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
|
||||
$('#capture').click();
|
||||
});
|
||||
if (profileIdRequest >= 0) {
|
||||
var promise = $.ajax({
|
||||
url: "getProfile?profileId=" + profileIdRequest,
|
||||
headers: { "session": sessionId }
|
||||
}).done(function (result) {
|
||||
handleDisplayProfileData(result);
|
||||
|
||||
$('#playerSaveButton').click(function () {
|
||||
var dataToUpload = {};
|
||||
@@ -109,20 +76,108 @@ function initPageLoadHandler() {
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#playerName').prop('disabled', true);
|
||||
$('#playerType').prop('disabled', true);
|
||||
$('#playerDifficulty').prop('disabled', true);
|
||||
$('#playerSaveButton').hide();
|
||||
$('#playerAvatar').unbind("click");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Save promise on page so the transition handler can find it.
|
||||
$(this).data('promise', promise);
|
||||
// Save promise on page so the transition handler can find it.
|
||||
$(this).data('promise', promise);
|
||||
}
|
||||
else {
|
||||
//new profile
|
||||
handleDisplayProfileData({
|
||||
"Avatar": { "base64Data": null },
|
||||
"Difficulty": 0,
|
||||
"IsEditable": true,
|
||||
"PlayerName": "YourName",
|
||||
"ProfileId": -1,
|
||||
"Type": 1
|
||||
});
|
||||
$('#playerType').prop("value", 0);
|
||||
$('#playerDifficulty').prop("value", 0);
|
||||
|
||||
$('#playerSaveButton').click(function () {
|
||||
var dataToUpload = {};
|
||||
|
||||
dataToUpload["ProfileId"] = -1;
|
||||
dataToUpload["PlayerName"] = $('#playerName').prop("value");
|
||||
dataToUpload["Type"] = $('#playerType').prop("value");
|
||||
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
|
||||
dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null;
|
||||
|
||||
$('#content').wrap('<div class="overlay" />');
|
||||
$.mobile.loading('show', {
|
||||
text: 'Creating profile...',
|
||||
textVisible: true
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: "sendProfile",
|
||||
dataType: "json",
|
||||
contentType: "application/json;charset=utf-8",
|
||||
type: "POST",
|
||||
headers: { "session": sessionId },
|
||||
data: JSON.stringify(dataToUpload),
|
||||
success: function (msg) {
|
||||
$.mobile.changePage("#login", { transition: "slidefade" });
|
||||
}
|
||||
}).always(function () {
|
||||
$.mobile.loading('hide');
|
||||
$('#content').unwrap();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function handleDisplayProfileData(data) {
|
||||
$('#playerName').prop("value", data.PlayerName);
|
||||
if (data.Avatar && data.Avatar.base64Data) {
|
||||
$('#playerAvatar').prop("src", data.Avatar.base64Data);
|
||||
}
|
||||
else {
|
||||
$('#playerAvatar').prop("src", "img/profile.png");
|
||||
}
|
||||
$('#playerAvatar').data("changed", false);
|
||||
$('#playerType').prop("value", data.Type);
|
||||
$('#playerDifficulty').prop("value", data.Difficulty);
|
||||
if (data.IsEditable) {
|
||||
$('#playerName').prop('disabled', false);
|
||||
$('#playerType').prop('disabled', false);
|
||||
$('#playerDifficulty').prop('disabled', false);
|
||||
$('#playerSaveButton').show().unbind("click");
|
||||
$('#playerAvatar').unbind("click");
|
||||
|
||||
$('#playerAvatar').click(function () {
|
||||
if ($('#captureContainer').length > 0) {
|
||||
$('#captureContainer').remove();
|
||||
}
|
||||
|
||||
$(document.body).append('<div id="captureContainer" style="height: 0px;width:0px; overflow:hidden;"> <input type="file" accept="image/*" id="capture" capture> </div>');
|
||||
|
||||
$('#capture').change(function (eventData) {
|
||||
if (eventData && eventData.target && eventData.target.files && eventData.target.files.length == 1) {
|
||||
var file = eventData.target.files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onloadend = function (e) {
|
||||
$('#playerAvatar').prop("src", e.target.result);
|
||||
$('#playerAvatar').data("changed", true);
|
||||
$('#captureContainer').remove();
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
|
||||
$('#capture').click();
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#playerName').prop('disabled', true);
|
||||
$('#playerType').prop('disabled', true);
|
||||
$('#playerDifficulty').prop('disabled', true);
|
||||
$('#playerSaveButton').hide().unbind("click");
|
||||
$('#playerAvatar').unbind("click");
|
||||
}
|
||||
}
|
||||
|
||||
//pageLoadHandler for selectProfile
|
||||
$(document).on('pagebeforeshow', '#selectProfile', function () {
|
||||
var promise = $.ajax({
|
||||
@@ -278,11 +333,17 @@ function initLoginPageHandler() {
|
||||
}).fail(function (result) {
|
||||
$.mobile.loading('hide');
|
||||
$('#content').unwrap();
|
||||
});
|
||||
});
|
||||
}).fail(function (result) {
|
||||
$.mobile.loading('hide');
|
||||
$('#content').unwrap();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#registerButton').click(function () {
|
||||
ownProfileId = -1;
|
||||
profileIdRequest = -1;
|
||||
$.mobile.changePage("#displayProfile", { transition: "slidefade" });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user