Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime exception introduced by #148 #155

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions UT4MasterServer/Controllers/AdminPanelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UT4MasterServer.Authentication;
using UT4MasterServer.Helpers;
using UT4MasterServer.Models;
using UT4MasterServer.Models.Requests;
using UT4MasterServer.Other;
using UT4MasterServer.Services;

Expand Down Expand Up @@ -224,7 +225,7 @@ public async Task<IActionResult> DeleteTrustedServer(string id)
}

[HttpPatch("change_password/{id}")]
public async Task<IActionResult> ChangePassword(string id, [FromBody] string newPassword, [FromBody] bool? iAmSure)
public async Task<IActionResult> ChangePassword(string id, [FromBody] AdminPanelChangePasswordRequest body)
{
await VerifyAdmin();

Expand All @@ -240,23 +241,23 @@ public async Task<IActionResult> ChangePassword(string id, [FromBody] string new
}

// passwords should already be hashed, but check its length just in case
if (!ValidationHelper.ValidatePassword(newPassword))
if (!ValidationHelper.ValidatePassword(body.NewPassword))
{
return BadRequest(new ErrorResponse()
{
ErrorMessage = $"newPassword is not a SHA512 hash"
});
}

if (iAmSure != true)
if (body.IAmSure != true)
{
return BadRequest(new ErrorResponse()
{
ErrorMessage = $"'areYouSure' was not 'true'"
ErrorMessage = $"'iAmSure' was not 'true'"
});
}

await accountService.UpdateAccountPasswordAsync(account, newPassword);
await accountService.UpdateAccountPasswordAsync(account, body.NewPassword);

// logout user to make sure they remember they changed password by being forced to log in again,
// as well as prevent anyone else from using this account after successful password change.
Expand Down
12 changes: 12 additions & 0 deletions UT4MasterServer/Models/Requests/AdminPanelChangePasswordRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace UT4MasterServer.Models.Requests;

public class AdminPanelChangePasswordRequest
{
[JsonPropertyName("newPassword")]
public string NewPassword { get; set; } = string.Empty;

[JsonPropertyName("iAmSure")]
public bool? IAmSure { get; set; } = null;
}