diff --git a/ClientServerLib/ClientServerLib/CWebservice.cs b/ClientServerLib/ClientServerLib/CWebservice.cs
index 9e77c0bc..e6fa5f11 100644
--- a/ClientServerLib/ClientServerLib/CWebservice.cs
+++ b/ClientServerLib/ClientServerLib/CWebservice.cs
@@ -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)
diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs
index bd03e231..47f102ed 100644
--- a/Vocaluxe/Base/Server/CVocaluxeServer.cs
+++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs
@@ -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");
diff --git a/Vocaluxe/Website/index.html b/Vocaluxe/Website/index.html
index d322a01b..2f456753 100644
--- a/Vocaluxe/Website/index.html
+++ b/Vocaluxe/Website/index.html
@@ -23,6 +23,10 @@
Login
+
+
+
+ Create Profile
diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js
index 8b0bca97..740687a1 100644
--- a/Vocaluxe/Website/js/main.js
+++ b/Vocaluxe/Website/js/main.js
@@ -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('
');
-
- $('#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('');
+ $.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('
');
+
+ $('#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" });
});
}