]>
Commit | Line | Data |
---|---|---|
66357162 | 1 | import { Injectable } from '@angular/core' |
e309822b | 2 | import { Validators } from '@angular/forms' |
67ed6552 | 3 | import { BuildFormValidator } from './form-validator.service' |
e309822b C |
4 | |
5 | @Injectable() | |
6 | export class UserValidatorsService { | |
7 | readonly USER_USERNAME: BuildFormValidator | |
4abe9c59 | 8 | readonly USER_CHANNEL_NAME: BuildFormValidator |
e309822b C |
9 | readonly USER_EMAIL: BuildFormValidator |
10 | readonly USER_PASSWORD: BuildFormValidator | |
45f1bd72 | 11 | readonly USER_PASSWORD_OPTIONAL: BuildFormValidator |
b0ee41df | 12 | readonly USER_CONFIRM_PASSWORD: BuildFormValidator |
e309822b | 13 | readonly USER_VIDEO_QUOTA: BuildFormValidator |
bee0abff | 14 | readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator |
e309822b | 15 | readonly USER_ROLE: BuildFormValidator |
1f20622f | 16 | readonly USER_DISPLAY_NAME_REQUIRED: BuildFormValidator |
e309822b | 17 | readonly USER_DESCRIPTION: BuildFormValidator |
b4a929ac | 18 | readonly USER_TERMS: BuildFormValidator |
e309822b | 19 | |
141b177d C |
20 | readonly USER_BAN_REASON: BuildFormValidator |
21 | ||
66357162 | 22 | constructor () { |
e309822b C |
23 | |
24 | this.USER_USERNAME = { | |
25 | VALIDATORS: [ | |
26 | Validators.required, | |
d0ce42c1 BY |
27 | Validators.minLength(1), |
28 | Validators.maxLength(50), | |
6ebfaf67 | 29 | Validators.pattern(/^[a-z0-9][a-z0-9._]*$/) |
e309822b C |
30 | ], |
31 | MESSAGES: { | |
66357162 C |
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.` | |
e309822b C |
36 | } |
37 | } | |
38 | ||
4abe9c59 | 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: { | |
66357162 C |
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.` | |
4abe9c59 | 51 | } |
52 | } | |
53 | ||
e309822b C |
54 | this.USER_EMAIL = { |
55 | VALIDATORS: [ Validators.required, Validators.email ], | |
56 | MESSAGES: { | |
66357162 C |
57 | 'required': $localize`Email is required.`, |
58 | 'email': $localize`Email must be valid.` | |
e309822b C |
59 | } |
60 | } | |
61 | ||
62 | this.USER_PASSWORD = { | |
63 | VALIDATORS: [ | |
64 | Validators.required, | |
65 | Validators.minLength(6), | |
66 | Validators.maxLength(255) | |
67 | ], | |
68 | MESSAGES: { | |
66357162 C |
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.` | |
e309822b C |
72 | } |
73 | } | |
74 | ||
45f1bd72 JL |
75 | this.USER_PASSWORD_OPTIONAL = { |
76 | VALIDATORS: [ | |
77 | Validators.minLength(6), | |
78 | Validators.maxLength(255) | |
79 | ], | |
80 | MESSAGES: { | |
66357162 C |
81 | 'minlength': $localize`Password must be at least 6 characters long.`, |
82 | 'maxlength': $localize`Password cannot be more than 255 characters long.` | |
45f1bd72 JL |
83 | } |
84 | } | |
85 | ||
b0ee41df C |
86 | this.USER_CONFIRM_PASSWORD = { |
87 | VALIDATORS: [], | |
88 | MESSAGES: { | |
66357162 | 89 | 'matchPassword': $localize`The new password and the confirmed password do not correspond.` |
b0ee41df C |
90 | } |
91 | } | |
92 | ||
e309822b C |
93 | this.USER_VIDEO_QUOTA = { |
94 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | |
95 | MESSAGES: { | |
66357162 C |
96 | 'required': $localize`Video quota is required.`, |
97 | 'min': $localize`Quota must be greater than -1.` | |
e309822b C |
98 | } |
99 | } | |
bee0abff FA |
100 | this.USER_VIDEO_QUOTA_DAILY = { |
101 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | |
102 | MESSAGES: { | |
66357162 C |
103 | 'required': $localize`Daily upload limit is required.`, |
104 | 'min': $localize`Daily upload limit must be greater than -1.` | |
bee0abff FA |
105 | } |
106 | } | |
e309822b C |
107 | |
108 | this.USER_ROLE = { | |
109 | VALIDATORS: [ Validators.required ], | |
110 | MESSAGES: { | |
66357162 | 111 | 'required': $localize`User role is required.` |
e309822b C |
112 | } |
113 | } | |
114 | ||
1f20622f | 115 | this.USER_DISPLAY_NAME_REQUIRED = this.getDisplayName(true) |
e309822b C |
116 | |
117 | this.USER_DESCRIPTION = { | |
118 | VALIDATORS: [ | |
119 | Validators.minLength(3), | |
d23e6a1c | 120 | Validators.maxLength(1000) |
e309822b C |
121 | ], |
122 | MESSAGES: { | |
66357162 C |
123 | 'minlength': $localize`Description must be at least 3 characters long.`, |
124 | 'maxlength': $localize`Description cannot be more than 1000 characters long.` | |
e309822b C |
125 | } |
126 | } | |
b4a929ac C |
127 | |
128 | this.USER_TERMS = { | |
129 | VALIDATORS: [ | |
130 | Validators.requiredTrue | |
131 | ], | |
132 | MESSAGES: { | |
66357162 | 133 | 'required': $localize`You must agree with the instance terms in order to register on it.` |
b4a929ac C |
134 | } |
135 | } | |
141b177d C |
136 | |
137 | this.USER_BAN_REASON = { | |
138 | VALIDATORS: [ | |
139 | Validators.minLength(3), | |
140 | Validators.maxLength(250) | |
141 | ], | |
142 | MESSAGES: { | |
66357162 C |
143 | 'minlength': $localize`Ban reason must be at least 3 characters long.`, |
144 | 'maxlength': $localize`Ban reason cannot be more than 250 characters long.` | |
141b177d C |
145 | } |
146 | } | |
e309822b | 147 | } |
1f20622f C |
148 | |
149 | private getDisplayName (required: boolean) { | |
150 | const control = { | |
151 | VALIDATORS: [ | |
152 | Validators.minLength(1), | |
153 | Validators.maxLength(120) | |
154 | ], | |
155 | MESSAGES: { | |
66357162 C |
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.` | |
1f20622f C |
159 | } |
160 | } | |
161 | ||
162 | if (required) control.VALIDATORS.push(Validators.required) | |
163 | ||
164 | return control | |
165 | } | |
e309822b | 166 | } |