mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: account deletion; auto incremental uids; display name renaming UI + account deletion UI; enhanced username validation
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SharpbinV3.Server.DTOs
|
||||
{
|
||||
public class RegisterRequest
|
||||
public partial class RegisterRequest
|
||||
{
|
||||
[Required]
|
||||
[StringLength(50, MinimumLength = 3)]
|
||||
@@ -16,5 +17,30 @@ namespace SharpbinV3.Server.DTOs
|
||||
|
||||
public string? DisplayName { get; set; }
|
||||
public string? Token { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate()
|
||||
{
|
||||
var results = new List<ValidationResult>();
|
||||
if (!ValidateUsername().IsMatch(Username))
|
||||
results.Add(new ValidationResult("Username can only contain letters, numbers, underscores, and dots.", [nameof(Username)]));
|
||||
|
||||
if (DisplayName != null)
|
||||
{
|
||||
if (DisplayName.Length < 3 || DisplayName.Length > 26)
|
||||
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)]));
|
||||
}
|
||||
if (Email != null)
|
||||
{
|
||||
var emailAttribute = new EmailAddressAttribute();
|
||||
if (!emailAttribute.IsValid(Email))
|
||||
results.Add(new ValidationResult("Invalid email format.", [nameof(Email)]));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
[GeneratedRegex("^[A-Za-z0-9_.]+$")]
|
||||
private static partial Regex ValidateUsername();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SharpbinV3.Server.DTOs
|
||||
{
|
||||
public class UpdateUserRequest
|
||||
public partial class UpdateUserRequest
|
||||
{
|
||||
public string? DisplayName { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public int? Visibility { get; set; } = 0;
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
public IEnumerable<ValidationResult> Validate()
|
||||
{
|
||||
var results = new List<ValidationResult>();
|
||||
if (DisplayName != null) {
|
||||
if (DisplayName != null)
|
||||
{
|
||||
if (DisplayName.Length < 3 || DisplayName.Length > 26)
|
||||
{
|
||||
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)]));
|
||||
}
|
||||
if (Email != null)
|
||||
{
|
||||
var emailAttribute = new EmailAddressAttribute();
|
||||
if (!emailAttribute.IsValid(Email))
|
||||
{
|
||||
results.Add(new ValidationResult("Invalid email format.", [nameof(Email)]));
|
||||
}
|
||||
}
|
||||
if (Visibility != null)
|
||||
{
|
||||
if (Visibility < 0 || Visibility > 2)
|
||||
{
|
||||
results.Add(new ValidationResult("Visibility must be between 0 and 2.", [nameof(Visibility)]));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
[GeneratedRegex("^[A-Za-z0-9_.]+$")]
|
||||
private static partial Regex ValidateDisplayname();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user