From 0540df26c43a103c02091234c71b97c2855dacab Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Fri, 10 Mar 2023 05:42:54 +0500 Subject: [PATCH] edit validate user registration --- AsbCloudApp/Data/UserDto.cs | 11 ++++++--- AsbCloudApp/Data/UserRegistrationDto.cs | 6 ++++- .../UserRegistrationDtoValidator.cs | 24 ------------------- 3 files changed, 13 insertions(+), 28 deletions(-) delete mode 100644 AsbCloudInfrastructure/Validators/UserRegistrationDtoValidator.cs diff --git a/AsbCloudApp/Data/UserDto.cs b/AsbCloudApp/Data/UserDto.cs index e988f7e4..bff9d61e 100644 --- a/AsbCloudApp/Data/UserDto.cs +++ b/AsbCloudApp/Data/UserDto.cs @@ -13,40 +13,45 @@ namespace AsbCloudApp.Data /// /// логин /// - [Required] - [StringLength(255, MinimumLength = 2)] + [Required(ErrorMessage = "Логин не должен быть пустым")] + [StringLength(50, MinimumLength = 1, ErrorMessage = "Допустимая длина логина от 1 до 50 символов")] public string Login { get; set; } = null!; /// /// Имя /// + [StringLength(50, MinimumLength = 0, ErrorMessage = "Допустимая длина имени от 1 до 50 символов")] public string? Name { get; set; } /// /// Фамилия /// + [StringLength(50, MinimumLength = 0, ErrorMessage = "Допустимая длина фамилии от 1 до 50 символов")] public string? Surname { get; set; } /// /// Отчество /// + [StringLength(50, MinimumLength = 0, ErrorMessage = "Допустимая длина отчества от 1 до 50 символов")] public string? Patronymic { get; set; } /// /// Email /// [Required] - [StringLength(255, MinimumLength = 6)] + [StringLength(260, MinimumLength = 1, ErrorMessage = "Допустимая длина email от 1 до 260 символов")] public string Email { get; set; } = null!; /// /// Phone /// + [StringLength(50, MinimumLength = 1, ErrorMessage = "Допустимая длина телефона от 1 до 50 символов")] public string? Phone { get; set; } /// /// Должность /// + [StringLength(100, MinimumLength = 1, ErrorMessage = "Допустимая длина должности от 1 до 100 символов")] public string? Position { get; set; } /// diff --git a/AsbCloudApp/Data/UserRegistrationDto.cs b/AsbCloudApp/Data/UserRegistrationDto.cs index b919f9cf..da17cc0c 100644 --- a/AsbCloudApp/Data/UserRegistrationDto.cs +++ b/AsbCloudApp/Data/UserRegistrationDto.cs @@ -1,4 +1,6 @@ -namespace AsbCloudApp.Data +using System.ComponentModel.DataAnnotations; + +namespace AsbCloudApp.Data { /// public class UserRegistrationDto : UserDto @@ -6,6 +8,8 @@ /// /// пароль, используется только при регистрации. /// + [Required(ErrorMessage = "Пароль не должен быть пустым")] + [StringLength(50, MinimumLength = 1, ErrorMessage = "Допустимая длина пароля от 1 до 50 символов")] public string Password { get; set; } = null!; } } diff --git a/AsbCloudInfrastructure/Validators/UserRegistrationDtoValidator.cs b/AsbCloudInfrastructure/Validators/UserRegistrationDtoValidator.cs deleted file mode 100644 index 6e1ea0f7..00000000 --- a/AsbCloudInfrastructure/Validators/UserRegistrationDtoValidator.cs +++ /dev/null @@ -1,24 +0,0 @@ -using AsbCloudApp.Data; -using FluentValidation; - -namespace AsbCloudInfrastructure.Validators -{ - public class UserRegistrationDtoValidator : AbstractValidator - { - public UserRegistrationDtoValidator() - { - //RuleFor(x => x.Login).NotNull().WithMessage("Логин не должен быть пустым"); - //RuleFor(x => x.Login).NotEmpty().WithMessage("Логин не должен быть пустым"); - //RuleFor(x => x.Login).Length(0, 50).WithMessage("Допустимая длина логина от 1 до 50 символов"); - //RuleFor(x => x.Password).NotNull().WithMessage("Пароль не должен быть пустым"); - //RuleFor(x => x.Password).NotEmpty().WithMessage("Пароль не должен быть пустым"); - //RuleFor(x => x.Password).Length(0, 50).WithMessage("Допустимая длина Пароль от 1 до 50 символов"); - //RuleFor(x => x.Name).Length(0, 50).WithMessage("Допустимая длина имени от 1 до 50 символов"); - //RuleFor(x => x.Surname).Length(0, 50).WithMessage("Допустимая длина фамилии от 1 до 50 символов"); - //RuleFor(x => x.Patronymic).Length(0, 50).WithMessage("Допустимая длина отчества от 1 до 50 символов"); - //RuleFor(x => x.Email).Length(0, 260).WithMessage("Допустимая длина email от 1 до 260 символов"); - //RuleFor(x => x.Phone).Length(0, 50).WithMessage("Допустимая длина телефона от 1 до 50 символов"); - //RuleFor(x => x.Position).Length(0, 100).WithMessage("Допустимая длина должности от 1 до 100 символов"); - } - } -} \ No newline at end of file