Webserver:

-fix: Creating a player fails
-fix: Some error messages appear, even all is fine
-mod: removed the password set function (setting password is now a profile change)
This commit is contained in:
lukeIam committed 2013-12-13 18:02:56 +01:00
1 parent a69dd4344d
commit 38c506cd18
4 files changed
+48 -47

No files matched your search

@@ -168,13 +168,6 @@ namespace ServerLib
#region user management
private static SetPasswordDelegate _SetPassword;
public static SetPasswordDelegate SetPassword
{
internal get { return CServer._SetPassword; }
set { CServer._SetPassword = value; }
}
private static ValidatePasswordDelegate _ValidatePassword;
public static ValidatePasswordDelegate ValidatePassword
{
+2 -12
View File
@@ -81,7 +81,8 @@ namespace ServerLib
if (profile.ProfileId != -1) //-1 is the id for a new profile
{
if (!(_CheckRight(EUserRights.EditAllProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profile.ProfileId))
if (!(_CheckRight(EUserRights.EditAllProfiles)
|| CSessionControl.GetUserIdFromSession(sessionKey) == profile.ProfileId))
{
return;
}
@@ -97,17 +98,6 @@ namespace ServerLib
return;
}
if (!string.IsNullOrEmpty(profile.Password))
{
int profileId = profile.ProfileId;
if (profileId == -1)
{
profileId = CServer.GetUserIdFromUsername(profile.PlayerName);
}
CServer.SetPassword(profileId, profile.Password);
}
CServer.SendProfileData(profile);
}
+21 -18
View File
@@ -205,7 +205,7 @@ namespace Vocaluxe.Base.Server
newProfile.Avatar = _AddAvatar(profile.Avatar);
}
else if (newProfile.Avatar == null)
else if (newProfile.Avatar == null || newProfile.Avatar.ID == -1)
{
newProfile.Avatar = CProfiles.GetAvatars().First();
@@ -234,6 +234,26 @@ namespace Vocaluxe.Base.Server
newProfile.GuestProfile = (EOffOn)profile.Type;
}
if (!string.IsNullOrEmpty(profile.Password))
{
if (profile.Password == "***__CLEAR_PASSWORD__***")
{
newProfile.PasswordSalt = null;
newProfile.PasswordHash = null;
}
else
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buffer = new byte[128];
rng.GetNonZeroBytes(buffer);
byte[] salt = buffer;
byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(profile.Password), salt);
newProfile.PasswordSalt = salt;
newProfile.PasswordHash = hashedPassword;
}
}
if (existingProfile != null)
{
CProfiles.EditProfile(newProfile);
@@ -588,23 +608,6 @@ namespace Vocaluxe.Base.Server
#region user management
private static void _SetPassword(int profileId, string newPassword)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
{
throw new ArgumentException("Invalid profileId");
}
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buffer = new byte[128];
rng.GetNonZeroBytes(buffer);
byte[] salt = buffer;
byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(newPassword), salt);
profile.PasswordSalt = salt;
profile.PasswordHash = hashedPassword;
}
private static bool _ValidatePassword(int profileId, string password)
{
+25 -10
View File
@@ -57,14 +57,22 @@ function initPageLoadHandler() {
dataToUpload["Type"] = $('#playerType').prop("value");
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null;
dataToUpload["Password"] = $('#playerPassword').prop("value") != "**oldPassword**" ? $('#playerPassword').prop("value") : null;
var pass = $('#playerPassword').prop("value");
if (pass != "***__oldPassword__***") {
if (pass == "") {
dataToUpload["Password"] = "***__CLEAR_PASSWORD__***";
} else {
dataToUpload["Password"] = pass;
}
} else {
dataToUpload["Password"] = null;
}
request({
url: "sendProfile",
dataType: "json",
contentType: "application/json;charset=utf-8",
type: "POST",
headers: { "session": sessionId },
data: JSON.stringify(dataToUpload),
}, "Uploading profile...").done(function () {
history.back();
@@ -97,14 +105,22 @@ function initPageLoadHandler() {
dataToUpload["Type"] = $('#playerType').prop("value");
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null;
dataToUpload["Password"] = $('#playerPassword').prop("value") != "**oldPassword**" ? $('#playerPassword').prop("value") : null;
var pass = $('#playerPassword').prop("value");
if (pass != "***__oldPassword__***") {
if (pass == "") {
dataToUpload["Password"] = "***__CLEAR_PASSWORD__***";
} else {
dataToUpload["Password"] = pass;
}
} else {
dataToUpload["Password"] = null;
}
request({
url: "sendProfile",
dataType: "json",
contentType: "application/json;charset=utf-8",
type: "POST",
headers: { "session": sessionId },
data: JSON.stringify(dataToUpload)
}, 'Creating profile...').done(function () {
$.mobile.changePage("#login", { transition: "slidefade" });
@@ -120,15 +136,15 @@ function initPageLoadHandler() {
addImage($('#playerAvatar')[0], data.Avatar, "img/profile.png");
$('#playerAvatar').data("changed", false);
$('#playerType').prop("value", data.Type);
$('#playerDifficulty').prop("value", data.Difficulty);
$('#playerType').prop("selectedIndex", data.Type).selectmenu("refresh");
$('#playerDifficulty').prop("selectedIndex", data.Difficulty).selectmenu("refresh");
if (data.IsEditable) {
$('#playerName').prop('disabled', false);
$('#playerType').prop('disabled', false);
$('#playerDifficulty').prop('disabled', false);
$('#playerSaveButton').show().unbind("click");
$('#playerAvatar').unbind("click");
$('#playerPassword').prop('disabled', false).parent().show();
$('#playerPassword').prop('disabled', false).prop("value", "***__oldPassword__***").parent().show();
$('#playerPasswordLabel').show();
$('#playerAvatar').click(function () {
@@ -736,7 +752,6 @@ function initMainPageHandler() {
reader.onloadend = function (e) {
request({
url: "sendPhoto",
dataType: "json",
contentType: "application/json;charset=utf-8",
type: "POST",
headers: { "session": sessionId },