11namespace FSH . Modules . Identity . Constants ;
22
3+ using FSH . Framework . Shared . Localization ;
4+ using Microsoft . Extensions . Localization ;
5+ using Microsoft . Extensions . DependencyInjection ;
6+ using System . Globalization ;
7+
38/// <summary>
4- /// Validation message string constants for the Identity module.
5- /// These keys are used directly as messages now, and will become .resx lookup keys
6- /// when localization is added .
9+ /// Validation message helper for the Identity module.
10+ /// Uses SharedResource.resx for localized validation messages.
11+ /// Methods accept an optional IStringLocalizer for runtime localization, falling back to English defaults .
712/// </summary>
813internal static class IdentityValidationMessages
914{
10- // ── Required ─────────────────────────────────────────────────────────────
11- public const string GroupIdRequired = "Group ID is required." ;
12- public const string GroupNameRequired = "Group name is required." ;
13- public const string UserIdRequired = "User ID is required." ;
14- public const string UserIdsRequired = "At least one user ID is required." ;
15- public const string UserIdsInvalid = "User IDs cannot be empty or whitespace." ;
16- public const string RoleIdRequired = "Role ID is required." ;
17- public const string RoleNameRequired = "Role name is required." ;
18- public const string SessionIdRequired = "Session ID is required." ;
19- public const string EmailRequired = "Email is required." ;
20- public const string FirstNameRequired = "First name is required." ;
21- public const string LastNameRequired = "Last name is required." ;
22- public const string PasswordRequired = "Password is required." ;
23- public const string PasswordConfirmationRequired = "Password confirmation is required." ;
24- public const string UsernameRequired = "Username is required." ;
25- public const string ConfirmationCodeRequired = "Confirmation code is required." ;
26- public const string TenantRequired = "Tenant is required." ;
27- public const string CurrentPasswordRequired = "Current password is required." ;
28- public const string NewPasswordRequired = "New password is required." ;
29- public const string UserRolesRequired = "User roles list is required." ;
30-
31- // ── Length ────────────────────────────────────────────────────────────────
32- public const string GroupNameMaxLength = "Group name must not exceed 256 characters." ;
33- public const string DescriptionMaxLength = "Description must not exceed 1024 characters." ;
34- public const string ReasonMaxLength = "Reason must not exceed 500 characters." ;
35- public const string PhoneNumberMaxLength = "Phone number must not exceed 20 characters." ;
36- public const string UsernameMinLength = "Username must be at least 3 characters." ;
37- public const string UsernameMaxLength = "Username must not exceed 50 characters." ;
38- public const string PasswordMinLength = "Password must be at least 6 characters." ;
39- public const string FirstNameMaxLength = "First name must not exceed 100 characters." ;
40- public const string LastNameMaxLength = "Last name must not exceed 100 characters." ;
15+ // ── Required — method uses localized format or falls back to default ─────────
16+ public static string Required ( string fieldName , IStringLocalizer < SharedResource > ? localizer = null )
17+ {
18+ var format = localizer ? [ nameof ( Required ) ] ?? "{0} is required." ;
19+ return string . Format ( CultureInfo . InvariantCulture , format , fieldName ) ;
20+ }
21+
22+ // ── Required — non-standard messages that don't fit the field-name pattern ─
23+ public static string UserIdsRequired ( IStringLocalizer < SharedResource > ? localizer = null ) =>
24+ localizer ? [ nameof ( UserIdsRequired ) ] ?? "At least one user ID is required." ;
25+
26+ public static string UserIdsInvalid ( IStringLocalizer < SharedResource > ? localizer = null ) =>
27+ localizer ? [ nameof ( UserIdsInvalid ) ] ?? "User IDs cannot be empty or whitespace." ;
28+
29+ // ── Length — methods use localized format '{0} must not exceed {1} characters.' when localized ──
30+ public static string MaxLength ( string fieldName , int max , IStringLocalizer < SharedResource > ? localizer = null )
31+ {
32+ var format = localizer ? [ nameof ( MaxLength ) ] ?? "{0} must not exceed {1} characters." ;
33+ return string . Format ( CultureInfo . InvariantCulture , format , fieldName , max ) ;
34+ }
35+
36+ public static string MinLength ( string fieldName , int min , IStringLocalizer < SharedResource > ? localizer = null )
37+ {
38+ var format = localizer ? [ nameof ( MinLength ) ] ?? "{0} must be at least {1} characters." ;
39+ return string . Format ( CultureInfo . InvariantCulture , format , fieldName , min ) ;
40+ }
4141
4242 // ── Format & rules ────────────────────────────────────────────────────────
43- public const string InvalidEmail = "A valid email address is required." ;
44- public const string PasswordsMustMatch = "Passwords do not match." ;
45- public const string NewPasswordMustDiffer = "New password must be different from the current password." ;
46- public const string PasswordInHistory = "This password has been used recently. Please choose a different password." ;
47- public const string ImageConflict = "You cannot upload a new image and delete the current one simultaneously." ;
48- }
43+ public static string InvalidEmail ( IStringLocalizer < SharedResource > ? localizer = null ) =>
44+ localizer ? [ nameof ( InvalidEmail ) ] ?? "A valid email address is required." ;
45+
46+ public static string PasswordsMustMatch ( IStringLocalizer < SharedResource > ? localizer = null ) =>
47+ localizer ? [ nameof ( PasswordsMustMatch ) ] ?? "Passwords do not match." ;
48+
49+ public static string NewPasswordMustDiffer ( IStringLocalizer < SharedResource > ? localizer = null ) =>
50+ localizer ? [ nameof ( NewPasswordMustDiffer ) ] ?? "New password must be different from the current password." ;
51+
52+ public static string PasswordInHistory ( IStringLocalizer < SharedResource > ? localizer = null ) =>
53+ localizer ? [ nameof ( PasswordInHistory ) ] ?? "This password has been used recently. Please choose a different password." ;
54+
55+ public static string ImageConflict ( IStringLocalizer < SharedResource > ? localizer = null ) =>
56+ localizer ? [ nameof ( ImageConflict ) ] ?? "You cannot upload a new image and delete the current one simultaneously." ;
57+ }
0 commit comments