From 270360a32f9b9217a1be1057058a61c57f578e95 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 31 Jan 2026 11:23:23 -0500 Subject: [PATCH] fix: add IValidateableObject interface to required DTO's ensuring model validation --- SharpbinV3.Server/Controllers/UserController.cs | 1 + SharpbinV3.Server/DTOs/User/RegisterUserDto.cs | 4 ++-- SharpbinV3.Server/DTOs/User/UpdateUserDto.cs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SharpbinV3.Server/Controllers/UserController.cs b/SharpbinV3.Server/Controllers/UserController.cs index 6be4745..edf39e8 100644 --- a/SharpbinV3.Server/Controllers/UserController.cs +++ b/SharpbinV3.Server/Controllers/UserController.cs @@ -60,6 +60,7 @@ namespace SharpbinV3.Server.Controllers [EnableRateLimiting("Strict")] public async Task UpdateByUUID(Guid uuid, [FromBody] UpdateUserDto updatedUser) { + Console.WriteLine($"{ModelState.IsValid}"); if (!ModelState.IsValid) return BadRequest(ModelState); diff --git a/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs b/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs index c59d9a6..0251791 100644 --- a/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs +++ b/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs @@ -3,7 +3,7 @@ using System.Text.RegularExpressions; namespace SharpbinV3.Server.DTOs { - public partial class RegisterUserDto + public partial class RegisterUserDto : IValidatableObject { [Required] [StringLength(50, MinimumLength = 3)] @@ -18,7 +18,7 @@ namespace SharpbinV3.Server.DTOs public string? DisplayName { get; set; } public string? Token { get; set; } - public IEnumerable Validate() + public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); if (!ValidateUsername().IsMatch(Username)) diff --git a/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs b/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs index ff24814..0ab863f 100644 --- a/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs +++ b/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs @@ -3,7 +3,7 @@ using System.Text.RegularExpressions; namespace SharpbinV3.Server.DTOs { - public partial class UpdateUserDto + public partial class UpdateUserDto : IValidatableObject { public string? DisplayName { get; set; } public string? Email { get; set; } @@ -11,7 +11,7 @@ namespace SharpbinV3.Server.DTOs public int[]? Roles { get; set; } public string? TotpCode { get; set; } - public IEnumerable Validate() + public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); if (DisplayName != null)