diff --git a/UT4MasterServer/Controllers/AdminPanelController.cs b/UT4MasterServer/Controllers/AdminPanelController.cs index a7a16234..6d460c2b 100644 --- a/UT4MasterServer/Controllers/AdminPanelController.cs +++ b/UT4MasterServer/Controllers/AdminPanelController.cs @@ -2,6 +2,7 @@ using UT4MasterServer.Authentication; using UT4MasterServer.Helpers; using UT4MasterServer.Models; +using UT4MasterServer.Models.Requests; using UT4MasterServer.Other; using UT4MasterServer.Services; @@ -224,7 +225,7 @@ public async Task DeleteTrustedServer(string id) } [HttpPatch("change_password/{id}")] - public async Task ChangePassword(string id, [FromBody] string newPassword, [FromBody] bool? iAmSure) + public async Task ChangePassword(string id, [FromBody] AdminPanelChangePasswordRequest body) { await VerifyAdmin(); @@ -240,7 +241,7 @@ public async Task 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() { @@ -248,15 +249,15 @@ public async Task ChangePassword(string id, [FromBody] string new }); } - 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. diff --git a/UT4MasterServer/Models/Requests/AdminPanelChangePasswordRequest.cs b/UT4MasterServer/Models/Requests/AdminPanelChangePasswordRequest.cs new file mode 100644 index 00000000..38bda7ab --- /dev/null +++ b/UT4MasterServer/Models/Requests/AdminPanelChangePasswordRequest.cs @@ -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; +}