2024-12-11 21:36:30 +01:00
|
|
|
// <copyright file="AuthenticateUserValidator.cs" company="alveus.dev">
|
|
|
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
using Astral.Services.Dtos;
|
|
|
|
using FluentValidation;
|
|
|
|
using Injectio.Attributes;
|
|
|
|
|
|
|
|
namespace Astral.Services.Validators;
|
|
|
|
|
|
|
|
/// <summary>
|
2024-12-14 17:31:17 +01:00
|
|
|
/// Validation for <see cref="PasswordAuthenticateDto" />.
|
2024-12-11 21:36:30 +01:00
|
|
|
/// </summary>
|
|
|
|
[RegisterScoped]
|
2024-12-14 17:31:17 +01:00
|
|
|
public class AuthenticateUserValidator : AbstractValidator<PasswordAuthenticateDto>
|
2024-12-11 21:36:30 +01:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|