diff options
Diffstat (limited to 'client/src/app/shared/form-validators/user-validators.ts')
-rw-r--r-- | client/src/app/shared/form-validators/user-validators.ts | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/client/src/app/shared/form-validators/user-validators.ts b/client/src/app/shared/form-validators/user-validators.ts new file mode 100644 index 000000000..18199505c --- /dev/null +++ b/client/src/app/shared/form-validators/user-validators.ts | |||
@@ -0,0 +1,144 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | import { BuildFormValidator } from './form-validator.model' | ||
3 | |||
4 | export const USER_USERNAME_VALIDATOR: BuildFormValidator = { | ||
5 | VALIDATORS: [ | ||
6 | Validators.required, | ||
7 | Validators.minLength(1), | ||
8 | Validators.maxLength(50), | ||
9 | Validators.pattern(/^[a-z0-9][a-z0-9._]*$/) | ||
10 | ], | ||
11 | MESSAGES: { | ||
12 | 'required': $localize`Username is required.`, | ||
13 | 'minlength': $localize`Username must be at least 1 character long.`, | ||
14 | 'maxlength': $localize`Username cannot be more than 50 characters long.`, | ||
15 | 'pattern': $localize`Username should be lowercase alphanumeric; dots and underscores are allowed.` | ||
16 | } | ||
17 | } | ||
18 | |||
19 | export const USER_CHANNEL_NAME_VALIDATOR: BuildFormValidator = { | ||
20 | VALIDATORS: [ | ||
21 | Validators.required, | ||
22 | Validators.minLength(1), | ||
23 | Validators.maxLength(50), | ||
24 | Validators.pattern(/^[a-z0-9][a-z0-9._]*$/) | ||
25 | ], | ||
26 | MESSAGES: { | ||
27 | 'required': $localize`Channel name is required.`, | ||
28 | 'minlength': $localize`Channel name must be at least 1 character long.`, | ||
29 | 'maxlength': $localize`Channel name cannot be more than 50 characters long.`, | ||
30 | 'pattern': $localize`Channel name should be lowercase alphanumeric; dots and underscores are allowed.` | ||
31 | } | ||
32 | } | ||
33 | |||
34 | export const USER_EMAIL_VALIDATOR: BuildFormValidator = { | ||
35 | VALIDATORS: [ Validators.required, Validators.email ], | ||
36 | MESSAGES: { | ||
37 | 'required': $localize`Email is required.`, | ||
38 | 'email': $localize`Email must be valid.` | ||
39 | } | ||
40 | } | ||
41 | |||
42 | export const USER_PASSWORD_VALIDATOR: BuildFormValidator = { | ||
43 | VALIDATORS: [ | ||
44 | Validators.required, | ||
45 | Validators.minLength(6), | ||
46 | Validators.maxLength(255) | ||
47 | ], | ||
48 | MESSAGES: { | ||
49 | 'required': $localize`Password is required.`, | ||
50 | 'minlength': $localize`Password must be at least 6 characters long.`, | ||
51 | 'maxlength': $localize`Password cannot be more than 255 characters long.` | ||
52 | } | ||
53 | } | ||
54 | |||
55 | export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = { | ||
56 | VALIDATORS: [ | ||
57 | Validators.minLength(6), | ||
58 | Validators.maxLength(255) | ||
59 | ], | ||
60 | MESSAGES: { | ||
61 | 'minlength': $localize`Password must be at least 6 characters long.`, | ||
62 | 'maxlength': $localize`Password cannot be more than 255 characters long.` | ||
63 | } | ||
64 | } | ||
65 | |||
66 | export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = { | ||
67 | VALIDATORS: [], | ||
68 | MESSAGES: { | ||
69 | 'matchPassword': $localize`The new password and the confirmed password do not correspond.` | ||
70 | } | ||
71 | } | ||
72 | |||
73 | export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = { | ||
74 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
75 | MESSAGES: { | ||
76 | 'required': $localize`Video quota is required.`, | ||
77 | 'min': $localize`Quota must be greater than -1.` | ||
78 | } | ||
79 | } | ||
80 | export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = { | ||
81 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
82 | MESSAGES: { | ||
83 | 'required': $localize`Daily upload limit is required.`, | ||
84 | 'min': $localize`Daily upload limit must be greater than -1.` | ||
85 | } | ||
86 | } | ||
87 | |||
88 | export const USER_ROLE_VALIDATOR: BuildFormValidator = { | ||
89 | VALIDATORS: [ Validators.required ], | ||
90 | MESSAGES: { | ||
91 | 'required': $localize`User role is required.` | ||
92 | } | ||
93 | } | ||
94 | |||
95 | export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true) | ||
96 | |||
97 | export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = { | ||
98 | VALIDATORS: [ | ||
99 | Validators.minLength(3), | ||
100 | Validators.maxLength(1000) | ||
101 | ], | ||
102 | MESSAGES: { | ||
103 | 'minlength': $localize`Description must be at least 3 characters long.`, | ||
104 | 'maxlength': $localize`Description cannot be more than 1000 characters long.` | ||
105 | } | ||
106 | } | ||
107 | |||
108 | export const USER_TERMS_VALIDATOR: BuildFormValidator = { | ||
109 | VALIDATORS: [ | ||
110 | Validators.requiredTrue | ||
111 | ], | ||
112 | MESSAGES: { | ||
113 | 'required': $localize`You must agree with the instance terms in order to register on it.` | ||
114 | } | ||
115 | } | ||
116 | |||
117 | export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = { | ||
118 | VALIDATORS: [ | ||
119 | Validators.minLength(3), | ||
120 | Validators.maxLength(250) | ||
121 | ], | ||
122 | MESSAGES: { | ||
123 | 'minlength': $localize`Ban reason must be at least 3 characters long.`, | ||
124 | 'maxlength': $localize`Ban reason cannot be more than 250 characters long.` | ||
125 | } | ||
126 | } | ||
127 | |||
128 | function buildDisplayNameValidator (required: boolean) { | ||
129 | const control = { | ||
130 | VALIDATORS: [ | ||
131 | Validators.minLength(1), | ||
132 | Validators.maxLength(120) | ||
133 | ], | ||
134 | MESSAGES: { | ||
135 | 'required': $localize`Display name is required.`, | ||
136 | 'minlength': $localize`Display name must be at least 1 character long.`, | ||
137 | 'maxlength': $localize`Display name cannot be more than 50 characters long.` | ||
138 | } | ||
139 | } | ||
140 | |||
141 | if (required) control.VALIDATORS.push(Validators.required) | ||
142 | |||
143 | return control | ||
144 | } | ||