29 lines
1,006 B
C#
29 lines
1,006 B
C#
using FluentValidation;
|
|
using Galaeth.Services.Dtos;
|
|
using Injectio.Attributes;
|
|
|
|
namespace Galaeth.Services.Validators;
|
|
|
|
/// <summary>
|
|
/// Validation for <see cref="AuthenticateUserDto"/>.
|
|
/// </summary>
|
|
[RegisterScoped]
|
|
public class AuthenticateUserValidator : AbstractValidator<AuthenticateUserDto>
|
|
{
|
|
private const int MinimumUsernameLength = 4;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AuthenticateUserValidator"/> class.
|
|
/// </summary>
|
|
public AuthenticateUserValidator()
|
|
{
|
|
RuleFor(dto => dto.Username).NotEmpty().WithMessage("Username must be provided")
|
|
.MinimumLength(MinimumUsernameLength)
|
|
.WithMessage("Username must be a minimum of " + MinimumUsernameLength + " characters")
|
|
.Matches(@"^[A-Za-z0-9._-]+$")
|
|
.WithMessage("Username can only contain letters, numbers, hyphens, dashes and periods.");
|
|
|
|
RuleFor(dto => dto.Password).NotEmpty().WithMessage("Password must be provided");
|
|
}
|
|
}
|