Fixed ProfileAccess over webserver
This commit is contained in:
1 parent
c29ae91379
commit
eca41bab2f
4 files changed
+135
-57
No files matched your search
@@ -181,11 +181,14 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = getSession();
|
||||||
|
|
||||||
if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
|
if (profile.ProfileId != -1) //-1 is the id for a new profile
|
||||||
SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId))
|
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
|
||||||
return false;
|
SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId))
|
||||||
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CServer.SendProfileData == null)
|
if (CServer.SendProfileData == null)
|
||||||
|
|||||||
@@ -197,7 +197,12 @@ namespace Vocaluxe.Base.Server
|
|||||||
}
|
}
|
||||||
else if (newProfile.Avatar == null)
|
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 != "")
|
if (profile.PlayerName != null && profile.PlayerName != "")
|
||||||
@@ -214,6 +219,11 @@ namespace Vocaluxe.Base.Server
|
|||||||
newProfile.Difficulty = (EGameDifficulty)profile.Difficulty;
|
newProfile.Difficulty = (EGameDifficulty)profile.Difficulty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (profile.Type >= 0 && profile.Type <= 1)
|
||||||
|
{
|
||||||
|
newProfile.GuestProfile = (EOffOn)profile.Type;
|
||||||
|
}
|
||||||
|
|
||||||
if (existingProfile != null)
|
if (existingProfile != null)
|
||||||
{
|
{
|
||||||
CProfiles.EditProfile(newProfile);
|
CProfiles.EditProfile(newProfile);
|
||||||
@@ -484,8 +494,8 @@ namespace Vocaluxe.Base.Server
|
|||||||
private static int getUserIdFromUsername(string username)
|
private static int getUserIdFromUsername(string username)
|
||||||
{
|
{
|
||||||
var playerIds = (from p in CProfiles.GetProfiles()
|
var playerIds = (from p in CProfiles.GetProfiles()
|
||||||
where String.Equals(p.PlayerName, username,StringComparison.OrdinalIgnoreCase)
|
where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase)
|
||||||
select p.ID);
|
select p.ID);
|
||||||
if (playerIds.Count() == 0)
|
if (playerIds.Count() == 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Invalid playername");
|
throw new ArgumentException("Invalid playername");
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
<input type="text" id="loginPassword" name="loginPassword" data-mini="true">
|
<input type="text" id="loginPassword" name="loginPassword" data-mini="true">
|
||||||
<br />
|
<br />
|
||||||
<a data-role="button" id="loginButton">Login</a>
|
<a data-role="button" id="loginButton">Login</a>
|
||||||
|
<br />
|
||||||
|
<hr />
|
||||||
|
<br />
|
||||||
|
<a data-role="button" id="registerButton">Create Profile</a>
|
||||||
</div>
|
</div>
|
||||||
<!-- /content -->
|
<!-- /content -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+111
-50
@@ -38,45 +38,12 @@ function replaceTransitionHandler() {
|
|||||||
function initPageLoadHandler() {
|
function initPageLoadHandler() {
|
||||||
//pageLoadHandler for displayProfile
|
//pageLoadHandler for displayProfile
|
||||||
$(document).on('pagebeforeshow', '#displayProfile', function () {
|
$(document).on('pagebeforeshow', '#displayProfile', function () {
|
||||||
var promise = $.ajax({
|
if (profileIdRequest >= 0) {
|
||||||
url: "getProfile?profileId=" + profileIdRequest,
|
var promise = $.ajax({
|
||||||
headers: { "session": sessionId }
|
url: "getProfile?profileId=" + profileIdRequest,
|
||||||
}).done(function (result) {
|
headers: { "session": sessionId }
|
||||||
$('#playerName').prop("value", result.PlayerName);
|
}).done(function (result) {
|
||||||
if (result.Avatar && result.Avatar.base64Data) {
|
handleDisplayProfileData(result);
|
||||||
$('#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();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#playerSaveButton').click(function () {
|
$('#playerSaveButton').click(function () {
|
||||||
var dataToUpload = {};
|
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.
|
// Save promise on page so the transition handler can find it.
|
||||||
$(this).data('promise', promise);
|
$(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
|
//pageLoadHandler for selectProfile
|
||||||
$(document).on('pagebeforeshow', '#selectProfile', function () {
|
$(document).on('pagebeforeshow', '#selectProfile', function () {
|
||||||
var promise = $.ajax({
|
var promise = $.ajax({
|
||||||
@@ -284,6 +339,12 @@ function initLoginPageHandler() {
|
|||||||
$('#content').unwrap();
|
$('#content').unwrap();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#registerButton').click(function () {
|
||||||
|
ownProfileId = -1;
|
||||||
|
profileIdRequest = -1;
|
||||||
|
$.mobile.changePage("#displayProfile", { transition: "slidefade" });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initMainPageHandler() {
|
function initMainPageHandler() {
|
||||||
|
|||||||
Reference in new issue
Block a user