@@ -3,37 +3,71 @@ import i18n from "@/i18n";
33const t = i18n . global . t ;
44
55export const baseEmailRules = [
6- ( email : string ) => ! ! email || `${ t ( 'authentication.email' ) } ${ t ( 'validation.isRequired' ) } ` ,
7- ( email : string ) => email . length <= 64 || `${ t ( 'authentication.email' ) } ${ t ( 'validation.max64Characters' ) } `
8- ]
6+ ( email : string ) =>
7+ ! ! email || `${ t ( "authentication.email" ) } ${ t ( "validation.isRequired" ) } ` ,
8+ ( email : string ) =>
9+ email . length <= 64 ||
10+ `${ t ( "authentication.email" ) } ${ t ( "validation.max64Characters" ) } `
11+ ] ;
912
1013export const emailRules = baseEmailRules . concat ( [
11- ( email : string ) => / .+ @ .+ \. .+ / . test ( email ) || `${ t ( 'authentication.email' ) } ${ t ( 'validation.mustBeValid' ) } ` ,
14+ ( email : string ) =>
15+ / .+ @ .+ \. .+ / . test ( email ) ||
16+ `${ t ( "authentication.email" ) } ${ t ( "validation.mustBeValid" ) } `
1217] ) ;
1318
1419export const emailRulesSignIn = baseEmailRules . concat ( [
15- ( email : string ) => email === 'admin' || / .+ @ .+ \. .+ / . test ( email ) || `${ t ( 'authentication.email' ) } ${ t ( 'validation.mustBeValid' ) } ` ,
20+ ( email : string ) =>
21+ email === "admin" ||
22+ / .+ @ .+ \. .+ / . test ( email ) ||
23+ `${ t ( "authentication.email" ) } ${ t ( "validation.mustBeValid" ) } `
1624] ) ;
1725
1826export const newPasswordRules = [
19- ( password : string ) => ! ! password || `${ t ( 'authentication.password' ) } ${ t ( 'validation.isRequired' ) } ` ,
20- ( password : string ) => password . length >= 8 || `${ t ( 'authentication.password' ) } ${ t ( 'validation.min8Characters' ) } ` ,
21- ( password : string ) => password . length <= 64 || `${ t ( 'authentication.password' ) } ${ t ( 'validation.max64Characters' ) } ` ,
22- ( password : string ) => / (? = .* [ a - z ] ) / . test ( password ) || `${ t ( 'authentication.password' ) } ${ t ( 'validation.atLeastOneLower' ) } ` ,
23- ( password : string ) => / (? = .* [ A - Z ] ) / . test ( password ) || `${ t ( 'authentication.password' ) } ${ t ( 'validation.atLeastOneUpper' ) } ` ,
24- ( password : string ) => / (? = .* \d ) / . test ( password ) || `${ t ( 'authentication.password' ) } ${ t ( 'validation.atLeastOneDigit' ) } ` ,
25- ]
27+ ( password : string ) =>
28+ ! ! password ||
29+ `${ t ( "authentication.password" ) } ${ t ( "validation.isRequired" ) } ` ,
30+ ( password : string ) =>
31+ password . length >= 8 ||
32+ `${ t ( "authentication.password" ) } ${ t ( "validation.min8Characters" ) } ` ,
33+ ( password : string ) =>
34+ password . length <= 64 ||
35+ `${ t ( "authentication.password" ) } ${ t ( "validation.max64Characters" ) } ` ,
36+ ( password : string ) =>
37+ / (? = .* [ a - z ] ) / . test ( password ) ||
38+ `${ t ( "authentication.password" ) } ${ t ( "validation.atLeastOneLower" ) } ` ,
39+ ( password : string ) =>
40+ / (? = .* [ A - Z ] ) / . test ( password ) ||
41+ `${ t ( "authentication.password" ) } ${ t ( "validation.atLeastOneUpper" ) } ` ,
42+ ( password : string ) =>
43+ / (? = .* \d ) / . test ( password ) ||
44+ `${ t ( "authentication.password" ) } ${ t ( "validation.atLeastOneDigit" ) } `
45+ ] ;
46+
47+ export const updateUserPasswordRules = newPasswordRules . map (
48+ ( rule ) => ( password : string ) => ( password === "" ? true : rule ( password ) )
49+ ) ;
2650
2751export const currentPasswordRules = [
28- ( password : string ) => ! ! password || `${ t ( 'authentication.password' ) } ${ t ( 'validation.isRequired' ) } ` ,
29- ]
52+ ( password : string ) =>
53+ ! ! password ||
54+ `${ t ( "authentication.password" ) } ${ t ( "validation.isRequired" ) } `
55+ ] ;
3056
3157export const firstNameRules = [
32- ( firstName : string ) => ! ! firstName || `${ t ( 'authentication.firstName' ) } ${ t ( 'validation.isRequired' ) } ` ,
33- ( firstName : string ) => firstName . length <= 64 || `${ t ( 'authentication.firstName' ) } ${ t ( 'validation.max64Characters' ) } ` ,
34- ]
58+ ( firstName : string ) =>
59+ ! ! firstName ||
60+ `${ t ( "authentication.firstName" ) } ${ t ( "validation.isRequired" ) } ` ,
61+ ( firstName : string ) =>
62+ firstName . length <= 64 ||
63+ `${ t ( "authentication.firstName" ) } ${ t ( "validation.max64Characters" ) } `
64+ ] ;
3565
3666export const lastNameRules = [
37- ( lastName : string ) => ! ! lastName || `${ t ( 'authentication.lastName' ) } ${ t ( 'validation.isRequired' ) } ` ,
38- ( lastName : string ) => lastName . length <= 64 || `${ t ( 'authentication.lastName' ) } ${ t ( 'validation.max64Characters' ) } ` ,
39- ]
67+ ( lastName : string ) =>
68+ ! ! lastName ||
69+ `${ t ( "authentication.lastName" ) } ${ t ( "validation.isRequired" ) } ` ,
70+ ( lastName : string ) =>
71+ lastName . length <= 64 ||
72+ `${ t ( "authentication.lastName" ) } ${ t ( "validation.max64Characters" ) } `
73+ ] ;
0 commit comments