33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
|
// <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>
|
||
|
/// 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");
|
||
|
}
|
||
|
}
|