mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
@@ -7,7 +7,6 @@ namespace SharpbinV3.Server.DTOs.User
|
||||
[StringLength(50, MinimumLength = 3)]
|
||||
public string? Username { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[StringLength(128, MinimumLength = 6)]
|
||||
public string? Password { get; set; }
|
||||
public string? Token { get; set; }
|
||||
|
||||
@@ -22,36 +22,16 @@ namespace SharpbinV3.Server.DTOs
|
||||
{
|
||||
var results = new List<ValidationResult>();
|
||||
if (!ValidateUsername().IsMatch(Username))
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"Username can only contain letters, numbers, underscores, and dots.",
|
||||
[nameof(Username)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("Username can only contain letters, numbers, underscores, and dots.", [nameof(Username)]));
|
||||
if (!ValidatePassword().IsMatch(Password))
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"Password should have at least 8 characters, including uppercase, lowercase, and digits.",
|
||||
[nameof(Password)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("Password should have at least 8 characters, including uppercase, lowercase, and digits.", [nameof(Password)]));
|
||||
|
||||
if (DisplayName != null)
|
||||
{
|
||||
if (DisplayName.Length < 3 || DisplayName.Length > 26)
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"DisplayName must be between 3 and 26 characters.",
|
||||
[nameof(DisplayName)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("DisplayName must be between 3 and 26 characters.", [nameof(DisplayName)]));
|
||||
if (!ValidateUsername().IsMatch(DisplayName))
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"DisplayName can only contain letters, numbers, underscores, and dots.",
|
||||
[nameof(DisplayName)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("DisplayName can only contain letters, numbers, underscores, and dots.", [nameof(DisplayName)]));
|
||||
}
|
||||
if (Email != null)
|
||||
{
|
||||
@@ -64,7 +44,6 @@ namespace SharpbinV3.Server.DTOs
|
||||
|
||||
[GeneratedRegex("^[A-Za-z0-9_.]+$")]
|
||||
private static partial Regex ValidateUsername();
|
||||
|
||||
[GeneratedRegex("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$")]
|
||||
public static partial Regex ValidatePassword();
|
||||
}
|
||||
|
||||
@@ -17,19 +17,9 @@ namespace SharpbinV3.Server.DTOs
|
||||
if (DisplayName != null)
|
||||
{
|
||||
if (DisplayName.Length < 3 || DisplayName.Length > 26)
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"DisplayName must be between 3 and 26 characters.",
|
||||
[nameof(DisplayName)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("DisplayName must be between 3 and 26 characters.", [nameof(DisplayName)]));
|
||||
if (!ValidateDisplayname().IsMatch(DisplayName))
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"DisplayName can only contain letters, numbers, underscores, and dots.",
|
||||
[nameof(DisplayName)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("DisplayName can only contain letters, numbers, underscores, and dots.", [nameof(DisplayName)]));
|
||||
}
|
||||
if (Email != null)
|
||||
{
|
||||
@@ -40,27 +30,19 @@ namespace SharpbinV3.Server.DTOs
|
||||
if (Visibility != null)
|
||||
{
|
||||
if (Visibility < 0 || Visibility > 2)
|
||||
results.Add(
|
||||
new ValidationResult(
|
||||
"Visibility must be between 0 and 2.",
|
||||
[nameof(Visibility)]
|
||||
)
|
||||
);
|
||||
results.Add(new ValidationResult("Visibility must be between 0 and 2.", [nameof(Visibility)]));
|
||||
}
|
||||
if (Roles != null)
|
||||
{
|
||||
if (Roles.Length == 0)
|
||||
results.Add(
|
||||
new ValidationResult("Roles cannot be an empty array.", [nameof(Roles)])
|
||||
);
|
||||
results.Add(new ValidationResult("Roles cannot be an empty array.", [nameof(Roles)]));
|
||||
int[] validRoles = [0, 1, 255, 403];
|
||||
foreach (var role in Roles)
|
||||
{
|
||||
if (!validRoles.Contains(role))
|
||||
results.Add(
|
||||
new ValidationResult($"Invalid role: {role}.", [nameof(Roles)])
|
||||
);
|
||||
results.Add(new ValidationResult($"Invalid role: {role}.", [nameof(Roles)]));
|
||||
}
|
||||
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user