]>
Commit | Line | Data |
---|---|---|
1 | import { Validators } from '@angular/forms' | |
2 | import { BuildFormValidator } from './form-validator.model' | |
3 | ||
4 | export const USER_USERNAME_REGEX_CHARACTERS = '[a-z0-9][a-z0-9._]' | |
5 | ||
6 | export const USER_USERNAME_VALIDATOR: BuildFormValidator = { | |
7 | VALIDATORS: [ | |
8 | Validators.required, | |
9 | Validators.minLength(1), | |
10 | Validators.maxLength(50), | |
11 | Validators.pattern(new RegExp(`^${USER_USERNAME_REGEX_CHARACTERS}*$`)) | |
12 | ], | |
13 | MESSAGES: { | |
14 | required: $localize`Username is required.`, | |
15 | minlength: $localize`Username must be at least 1 character long.`, | |
16 | maxlength: $localize`Username cannot be more than 50 characters long.`, | |
17 | pattern: $localize`Username should be lowercase alphanumeric; dots and underscores are allowed.` | |
18 | } | |
19 | } | |
20 | ||
21 | export const USER_CHANNEL_NAME_VALIDATOR: BuildFormValidator = { | |
22 | VALIDATORS: [ | |
23 | Validators.required, | |
24 | Validators.minLength(1), | |
25 | Validators.maxLength(50), | |
26 | Validators.pattern(/^[a-z0-9][a-z0-9._]*$/) | |
27 | ], | |
28 | MESSAGES: { | |
29 | required: $localize`Channel name is required.`, | |
30 | minlength: $localize`Channel name must be at least 1 character long.`, | |
31 | maxlength: $localize`Channel name cannot be more than 50 characters long.`, | |
32 | pattern: $localize`Channel name should be lowercase, and can contain only alphanumeric characters, dots and underscores.` | |
33 | } | |
34 | } | |
35 | ||
36 | export const USER_EMAIL_VALIDATOR: BuildFormValidator = { | |
37 | VALIDATORS: [ Validators.required, Validators.email ], | |
38 | MESSAGES: { | |
39 | required: $localize`Email is required.`, | |
40 | email: $localize`Email must be valid.` | |
41 | } | |
42 | } | |
43 | ||
44 | export const USER_HANDLE_VALIDATOR: BuildFormValidator = { | |
45 | VALIDATORS: [ | |
46 | Validators.required, | |
47 | Validators.pattern(/@.+/) | |
48 | ], | |
49 | MESSAGES: { | |
50 | required: $localize`Handle is required.`, | |
51 | pattern: $localize`Handle must be valid (eg. chocobozzz@example.com).` | |
52 | } | |
53 | } | |
54 | ||
55 | export const USER_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = { | |
56 | VALIDATORS: [ | |
57 | Validators.required | |
58 | ], | |
59 | MESSAGES: { | |
60 | required: $localize`Password is required.` | |
61 | } | |
62 | } | |
63 | ||
64 | export const USER_OTP_TOKEN_VALIDATOR: BuildFormValidator = { | |
65 | VALIDATORS: [ | |
66 | Validators.required | |
67 | ], | |
68 | MESSAGES: { | |
69 | required: $localize`OTP token is required.` | |
70 | } | |
71 | } | |
72 | ||
73 | export const USER_PASSWORD_VALIDATOR = { | |
74 | VALIDATORS: [ | |
75 | Validators.required, | |
76 | Validators.minLength(6), | |
77 | Validators.maxLength(255) | |
78 | ], | |
79 | MESSAGES: { | |
80 | required: $localize`Password is required.`, | |
81 | minlength: $localize`Password must be at least 6 characters long.`, | |
82 | maxlength: $localize`Password cannot be more than 255 characters long.` | |
83 | } | |
84 | } | |
85 | ||
86 | export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = { | |
87 | VALIDATORS: [ | |
88 | Validators.minLength(6), | |
89 | Validators.maxLength(255) | |
90 | ], | |
91 | MESSAGES: { | |
92 | minlength: $localize`Password must be at least 6 characters long.`, | |
93 | maxlength: $localize`Password cannot be more than 255 characters long.` | |
94 | } | |
95 | } | |
96 | ||
97 | export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = { | |
98 | VALIDATORS: [], | |
99 | MESSAGES: { | |
100 | matchPassword: $localize`The new password and the confirmed password do not correspond.` | |
101 | } | |
102 | } | |
103 | ||
104 | export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = { | |
105 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | |
106 | MESSAGES: { | |
107 | required: $localize`Video quota is required.`, | |
108 | min: $localize`Quota must be greater than -1.` | |
109 | } | |
110 | } | |
111 | export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = { | |
112 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | |
113 | MESSAGES: { | |
114 | required: $localize`Daily upload limit is required.`, | |
115 | min: $localize`Daily upload limit must be greater than -1.` | |
116 | } | |
117 | } | |
118 | ||
119 | export const USER_ROLE_VALIDATOR: BuildFormValidator = { | |
120 | VALIDATORS: [ Validators.required ], | |
121 | MESSAGES: { | |
122 | required: $localize`User role is required.` | |
123 | } | |
124 | } | |
125 | ||
126 | export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true) | |
127 | ||
128 | export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = { | |
129 | VALIDATORS: [ | |
130 | Validators.minLength(3), | |
131 | Validators.maxLength(1000) | |
132 | ], | |
133 | MESSAGES: { | |
134 | minlength: $localize`Description must be at least 3 characters long.`, | |
135 | maxlength: $localize`Description cannot be more than 1000 characters long.` | |
136 | } | |
137 | } | |
138 | ||
139 | export const USER_TERMS_VALIDATOR: BuildFormValidator = { | |
140 | VALIDATORS: [ Validators.requiredTrue ], | |
141 | MESSAGES: { | |
142 | required: $localize`You must agree with the instance terms in order to register on it.` | |
143 | } | |
144 | } | |
145 | ||
146 | export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = { | |
147 | VALIDATORS: [ | |
148 | Validators.minLength(3), | |
149 | Validators.maxLength(250) | |
150 | ], | |
151 | MESSAGES: { | |
152 | minlength: $localize`Ban reason must be at least 3 characters long.`, | |
153 | maxlength: $localize`Ban reason cannot be more than 250 characters long.` | |
154 | } | |
155 | } | |
156 | ||
157 | function buildDisplayNameValidator (required: boolean) { | |
158 | const control = { | |
159 | VALIDATORS: [ | |
160 | Validators.minLength(1), | |
161 | Validators.maxLength(120) | |
162 | ], | |
163 | MESSAGES: { | |
164 | required: $localize`Display name is required.`, | |
165 | minlength: $localize`Display name must be at least 1 character long.`, | |
166 | maxlength: $localize`Display name cannot be more than 50 characters long.` | |
167 | } | |
168 | } | |
169 | ||
170 | if (required) control.VALIDATORS.push(Validators.required) | |
171 | ||
172 | return control | |
173 | } |