diff options
author | vnugent <public@vaughnnugent.com> | 2023-11-05 21:22:21 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-11-05 21:22:21 -0500 |
commit | 0316fc948dd77b91b0ccf508826f66a175cb1e83 (patch) | |
tree | fdcff17a84ceab87b405428f463d499b7960002c /plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs | |
parent | 218b867ec568f4002d8c18a565fc46e186d1322a (diff) |
user/acc updates and fix social oauth
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs b/plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs index 7ebb37e..0ccda69 100644 --- a/plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs +++ b/plugins/VNLib.Plugins.Essentials.SocialOauth/src/Validators/AccountDataValidator.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.SocialOauth @@ -27,8 +27,6 @@ using FluentValidation; using VNLib.Plugins.Essentials.Accounts; using VNLib.Plugins.Extensions.Validation; -#nullable enable - namespace VNLib.Plugins.Essentials.SocialOauth.Validators { internal class AccountDataValidator : AbstractValidator<AccountData> @@ -39,36 +37,47 @@ namespace VNLib.Plugins.Essentials.SocialOauth.Validators .NotEmpty() .WithMessage("Your account does not have an email address assigned to it"); - RuleFor(t => t.EmailAddress) - .EmailAddress() - .WithMessage("Your account does not have a valid email address assigned to it"); - - //Validate city - RuleFor(t => t.City).MaximumLength(50); - RuleFor(t => t.City).AlphaOnly(); - - RuleFor(t => t.Company).MaximumLength(50); - RuleFor(t => t.Company).SpecialCharacters(); + RuleFor(t => t.City) + .MaximumLength(35) + .AlphaOnly() + .When(t => t.City?.Length > 0); - RuleFor(t => t.First).MaximumLength(35); - RuleFor(t => t.First).AlphaOnly(); + RuleFor(t => t.Company) + .MaximumLength(50) + .SpecialCharacters() + .When(t => t.Company?.Length > 0); - RuleFor(t => t.Last).MaximumLength(35); - RuleFor(t => t.Last).AlphaOnly(); + //Require a first and last names to be set together + When(t => t.First?.Length > 0 || t.Last?.Length > 0, () => + { + RuleFor(t => t.First) + .Length(1, 35) + .AlphaOnly(); + RuleFor(t => t.Last) + .Length(1, 35) + .AlphaOnly(); + }); RuleFor(t => t.PhoneNumber) - .EmptyPhoneNumber() + .PhoneNumber() + .When(t => t.PhoneNumber?.Length > 0) .OverridePropertyName("Phone"); //State must be 2 characters for us states if set - RuleFor(t => t.State).Length(t => t.State?.Length != 0 ? 2 : 0); + RuleFor(t => t.State) + .Length(2) + .When(t => t.State?.Length > 0); - RuleFor(t => t.Street).MaximumLength(50); - RuleFor(t => t.Street).AlphaNumericOnly(); + RuleFor(t => t.Street) + .AlphaNumericOnly() + .MaximumLength(50) + .When(t => t.Street?.Length > 0); - RuleFor(t => t.Zip).NumericOnly(); //Allow empty zip codes, but if one is defined, is must be less than 7 characters - RuleFor(t => t.Zip).Length(ad => ad.Zip?.Length != 0 ? 7 : 0); + RuleFor(t => t.Zip) + .NumericOnly() + .MaximumLength(7) + .When(t => t.Zip?.Length > 0); } } } |