diff options
Diffstat (limited to 'client/src/app/shared/shared-forms/form-validators/user-validators.service.ts')
-rw-r--r-- | client/src/app/shared/shared-forms/form-validators/user-validators.service.ts | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/client/src/app/shared/shared-forms/form-validators/user-validators.service.ts b/client/src/app/shared/shared-forms/form-validators/user-validators.service.ts deleted file mode 100644 index 312fc9b1e..000000000 --- a/client/src/app/shared/shared-forms/form-validators/user-validators.service.ts +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { BuildFormValidator } from './form-validator.service' | ||
4 | |||
5 | @Injectable() | ||
6 | export class UserValidatorsService { | ||
7 | readonly USER_USERNAME: BuildFormValidator | ||
8 | readonly USER_CHANNEL_NAME: BuildFormValidator | ||
9 | readonly USER_EMAIL: BuildFormValidator | ||
10 | readonly USER_PASSWORD: BuildFormValidator | ||
11 | readonly USER_PASSWORD_OPTIONAL: BuildFormValidator | ||
12 | readonly USER_CONFIRM_PASSWORD: BuildFormValidator | ||
13 | readonly USER_VIDEO_QUOTA: BuildFormValidator | ||
14 | readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator | ||
15 | readonly USER_ROLE: BuildFormValidator | ||
16 | readonly USER_DISPLAY_NAME_REQUIRED: BuildFormValidator | ||
17 | readonly USER_DESCRIPTION: BuildFormValidator | ||
18 | readonly USER_TERMS: BuildFormValidator | ||
19 | |||
20 | readonly USER_BAN_REASON: BuildFormValidator | ||
21 | |||
22 | constructor () { | ||
23 | |||
24 | this.USER_USERNAME = { | ||
25 | VALIDATORS: [ | ||
26 | Validators.required, | ||
27 | Validators.minLength(1), | ||
28 | Validators.maxLength(50), | ||
29 | Validators.pattern(/^[a-z0-9][a-z0-9._]*$/) | ||
30 | ], | ||
31 | MESSAGES: { | ||
32 | 'required': $localize`Username is required.`, | ||
33 | 'minlength': $localize`Username must be at least 1 character long.`, | ||
34 | 'maxlength': $localize`Username cannot be more than 50 characters long.`, | ||
35 | 'pattern': $localize`Username should be lowercase alphanumeric; dots and underscores are allowed.` | ||
36 | } | ||
37 | } | ||
38 | |||
39 | this.USER_CHANNEL_NAME = { | ||
40 | VALIDATORS: [ | ||
41 | Validators.required, | ||
42 | Validators.minLength(1), | ||
43 | Validators.maxLength(50), | ||
44 | Validators.pattern(/^[a-z0-9][a-z0-9._]*$/) | ||
45 | ], | ||
46 | MESSAGES: { | ||
47 | 'required': $localize`Channel name is required.`, | ||
48 | 'minlength': $localize`Channel name must be at least 1 character long.`, | ||
49 | 'maxlength': $localize`Channel name cannot be more than 50 characters long.`, | ||
50 | 'pattern': $localize`Channel name should be lowercase alphanumeric; dots and underscores are allowed.` | ||
51 | } | ||
52 | } | ||
53 | |||
54 | this.USER_EMAIL = { | ||
55 | VALIDATORS: [ Validators.required, Validators.email ], | ||
56 | MESSAGES: { | ||
57 | 'required': $localize`Email is required.`, | ||
58 | 'email': $localize`Email must be valid.` | ||
59 | } | ||
60 | } | ||
61 | |||
62 | this.USER_PASSWORD = { | ||
63 | VALIDATORS: [ | ||
64 | Validators.required, | ||
65 | Validators.minLength(6), | ||
66 | Validators.maxLength(255) | ||
67 | ], | ||
68 | MESSAGES: { | ||
69 | 'required': $localize`Password is required.`, | ||
70 | 'minlength': $localize`Password must be at least 6 characters long.`, | ||
71 | 'maxlength': $localize`Password cannot be more than 255 characters long.` | ||
72 | } | ||
73 | } | ||
74 | |||
75 | this.USER_PASSWORD_OPTIONAL = { | ||
76 | VALIDATORS: [ | ||
77 | Validators.minLength(6), | ||
78 | Validators.maxLength(255) | ||
79 | ], | ||
80 | MESSAGES: { | ||
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 | this.USER_CONFIRM_PASSWORD = { | ||
87 | VALIDATORS: [], | ||
88 | MESSAGES: { | ||
89 | 'matchPassword': $localize`The new password and the confirmed password do not correspond.` | ||
90 | } | ||
91 | } | ||
92 | |||
93 | this.USER_VIDEO_QUOTA = { | ||
94 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
95 | MESSAGES: { | ||
96 | 'required': $localize`Video quota is required.`, | ||
97 | 'min': $localize`Quota must be greater than -1.` | ||
98 | } | ||
99 | } | ||
100 | this.USER_VIDEO_QUOTA_DAILY = { | ||
101 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
102 | MESSAGES: { | ||
103 | 'required': $localize`Daily upload limit is required.`, | ||
104 | 'min': $localize`Daily upload limit must be greater than -1.` | ||
105 | } | ||
106 | } | ||
107 | |||
108 | this.USER_ROLE = { | ||
109 | VALIDATORS: [ Validators.required ], | ||
110 | MESSAGES: { | ||
111 | 'required': $localize`User role is required.` | ||
112 | } | ||
113 | } | ||
114 | |||
115 | this.USER_DISPLAY_NAME_REQUIRED = this.getDisplayName(true) | ||
116 | |||
117 | this.USER_DESCRIPTION = { | ||
118 | VALIDATORS: [ | ||
119 | Validators.minLength(3), | ||
120 | Validators.maxLength(1000) | ||
121 | ], | ||
122 | MESSAGES: { | ||
123 | 'minlength': $localize`Description must be at least 3 characters long.`, | ||
124 | 'maxlength': $localize`Description cannot be more than 1000 characters long.` | ||
125 | } | ||
126 | } | ||
127 | |||
128 | this.USER_TERMS = { | ||
129 | VALIDATORS: [ | ||
130 | Validators.requiredTrue | ||
131 | ], | ||
132 | MESSAGES: { | ||
133 | 'required': $localize`You must agree with the instance terms in order to register on it.` | ||
134 | } | ||
135 | } | ||
136 | |||
137 | this.USER_BAN_REASON = { | ||
138 | VALIDATORS: [ | ||
139 | Validators.minLength(3), | ||
140 | Validators.maxLength(250) | ||
141 | ], | ||
142 | MESSAGES: { | ||
143 | 'minlength': $localize`Ban reason must be at least 3 characters long.`, | ||
144 | 'maxlength': $localize`Ban reason cannot be more than 250 characters long.` | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | private getDisplayName (required: boolean) { | ||
150 | const control = { | ||
151 | VALIDATORS: [ | ||
152 | Validators.minLength(1), | ||
153 | Validators.maxLength(120) | ||
154 | ], | ||
155 | MESSAGES: { | ||
156 | 'required': $localize`Display name is required.`, | ||
157 | 'minlength': $localize`Display name must be at least 1 character long.`, | ||
158 | 'maxlength': $localize`Display name cannot be more than 50 characters long.` | ||
159 | } | ||
160 | } | ||
161 | |||
162 | if (required) control.VALIDATORS.push(Validators.required) | ||
163 | |||
164 | return control | ||
165 | } | ||
166 | } | ||