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:
1 parent
a69dd4344d
commit
38c506cd18
4 files changed
+48
-47
No files matched your search
@@ -168,13 +168,6 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region user management
|
#region user management
|
||||||
|
|
||||||
private static SetPasswordDelegate _SetPassword;
|
|
||||||
public static SetPasswordDelegate SetPassword
|
|
||||||
{
|
|
||||||
internal get { return CServer._SetPassword; }
|
|
||||||
set { CServer._SetPassword = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ValidatePasswordDelegate _ValidatePassword;
|
private static ValidatePasswordDelegate _ValidatePassword;
|
||||||
public static ValidatePasswordDelegate ValidatePassword
|
public static ValidatePasswordDelegate ValidatePassword
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ namespace ServerLib
|
|||||||
|
|
||||||
if (profile.ProfileId != -1) //-1 is the id for a new profile
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,17 +98,6 @@ namespace ServerLib
|
|||||||
return;
|
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);
|
CServer.SendProfileData(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
newProfile.Avatar = _AddAvatar(profile.Avatar);
|
newProfile.Avatar = _AddAvatar(profile.Avatar);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (newProfile.Avatar == null)
|
else if (newProfile.Avatar == null || newProfile.Avatar.ID == -1)
|
||||||
{
|
{
|
||||||
newProfile.Avatar = CProfiles.GetAvatars().First();
|
newProfile.Avatar = CProfiles.GetAvatars().First();
|
||||||
|
|
||||||
@@ -234,6 +234,26 @@ namespace Vocaluxe.Base.Server
|
|||||||
newProfile.GuestProfile = (EOffOn)profile.Type;
|
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)
|
if (existingProfile != null)
|
||||||
{
|
{
|
||||||
CProfiles.EditProfile(newProfile);
|
CProfiles.EditProfile(newProfile);
|
||||||
@@ -588,23 +608,6 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
#region user management
|
#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)
|
private static bool _ValidatePassword(int profileId, string password)
|
||||||
{
|
{
|
||||||
|
|||||||
+25
-10
@@ -57,14 +57,22 @@ function initPageLoadHandler() {
|
|||||||
dataToUpload["Type"] = $('#playerType').prop("value");
|
dataToUpload["Type"] = $('#playerType').prop("value");
|
||||||
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
|
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
|
||||||
dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null;
|
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({
|
request({
|
||||||
url: "sendProfile",
|
url: "sendProfile",
|
||||||
dataType: "json",
|
|
||||||
contentType: "application/json;charset=utf-8",
|
contentType: "application/json;charset=utf-8",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
headers: { "session": sessionId },
|
|
||||||
data: JSON.stringify(dataToUpload),
|
data: JSON.stringify(dataToUpload),
|
||||||
}, "Uploading profile...").done(function () {
|
}, "Uploading profile...").done(function () {
|
||||||
history.back();
|
history.back();
|
||||||
@@ -97,14 +105,22 @@ function initPageLoadHandler() {
|
|||||||
dataToUpload["Type"] = $('#playerType').prop("value");
|
dataToUpload["Type"] = $('#playerType').prop("value");
|
||||||
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
|
dataToUpload["Difficulty"] = $('#playerDifficulty').prop("value");
|
||||||
dataToUpload["Avatar"] = $('#playerAvatar').data("changed") ? { "base64Data": $('#playerAvatar').prop("src") } : null;
|
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({
|
request({
|
||||||
url: "sendProfile",
|
url: "sendProfile",
|
||||||
dataType: "json",
|
|
||||||
contentType: "application/json;charset=utf-8",
|
contentType: "application/json;charset=utf-8",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
headers: { "session": sessionId },
|
|
||||||
data: JSON.stringify(dataToUpload)
|
data: JSON.stringify(dataToUpload)
|
||||||
}, 'Creating profile...').done(function () {
|
}, 'Creating profile...').done(function () {
|
||||||
$.mobile.changePage("#login", { transition: "slidefade" });
|
$.mobile.changePage("#login", { transition: "slidefade" });
|
||||||
@@ -120,15 +136,15 @@ function initPageLoadHandler() {
|
|||||||
addImage($('#playerAvatar')[0], data.Avatar, "img/profile.png");
|
addImage($('#playerAvatar')[0], data.Avatar, "img/profile.png");
|
||||||
|
|
||||||
$('#playerAvatar').data("changed", false);
|
$('#playerAvatar').data("changed", false);
|
||||||
$('#playerType').prop("value", data.Type);
|
$('#playerType').prop("selectedIndex", data.Type).selectmenu("refresh");
|
||||||
$('#playerDifficulty').prop("value", data.Difficulty);
|
$('#playerDifficulty').prop("selectedIndex", data.Difficulty).selectmenu("refresh");
|
||||||
if (data.IsEditable) {
|
if (data.IsEditable) {
|
||||||
$('#playerName').prop('disabled', false);
|
$('#playerName').prop('disabled', false);
|
||||||
$('#playerType').prop('disabled', false);
|
$('#playerType').prop('disabled', false);
|
||||||
$('#playerDifficulty').prop('disabled', false);
|
$('#playerDifficulty').prop('disabled', false);
|
||||||
$('#playerSaveButton').show().unbind("click");
|
$('#playerSaveButton').show().unbind("click");
|
||||||
$('#playerAvatar').unbind("click");
|
$('#playerAvatar').unbind("click");
|
||||||
$('#playerPassword').prop('disabled', false).parent().show();
|
$('#playerPassword').prop('disabled', false).prop("value", "***__oldPassword__***").parent().show();
|
||||||
$('#playerPasswordLabel').show();
|
$('#playerPasswordLabel').show();
|
||||||
|
|
||||||
$('#playerAvatar').click(function () {
|
$('#playerAvatar').click(function () {
|
||||||
@@ -736,7 +752,6 @@ function initMainPageHandler() {
|
|||||||
reader.onloadend = function (e) {
|
reader.onloadend = function (e) {
|
||||||
request({
|
request({
|
||||||
url: "sendPhoto",
|
url: "sendPhoto",
|
||||||
dataType: "json",
|
|
||||||
contentType: "application/json;charset=utf-8",
|
contentType: "application/json;charset=utf-8",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
headers: { "session": sessionId },
|
headers: { "session": sessionId },
|
||||||
|
|||||||
Reference in new issue
Block a user