]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/form-validators/user-validators.ts
Implement remote interaction
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / form-validators / user-validators.ts
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, and can contain only alphanumeric characters, dots and underscores.`
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_HANDLE_VALIDATOR: BuildFormValidator = {
43 VALIDATORS: [
44 Validators.required,
45 Validators.pattern(/@.+/)
46 ],
47 MESSAGES: {
48 'required': $localize`Handle is required.`,
49 'pattern': $localize`Handle must be valid (chocobozzz@example.com).`
50 }
51 }
52
53 export const USER_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = {
54 VALIDATORS: [
55 Validators.required
56 ],
57 MESSAGES: {
58 'required': $localize`Password is required.`
59 }
60 }
61
62 export const USER_PASSWORD_VALIDATOR: BuildFormValidator = {
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 export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = {
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 export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = {
87 VALIDATORS: [],
88 MESSAGES: {
89 'matchPassword': $localize`The new password and the confirmed password do not correspond.`
90 }
91 }
92
93 export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
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 export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = {
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 export const USER_ROLE_VALIDATOR: BuildFormValidator = {
109 VALIDATORS: [ Validators.required ],
110 MESSAGES: {
111 'required': $localize`User role is required.`
112 }
113 }
114
115 export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true)
116
117 export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = {
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 export const USER_TERMS_VALIDATOR: BuildFormValidator = {
129 VALIDATORS: [ Validators.requiredTrue ],
130 MESSAGES: {
131 'required': $localize`You must agree with the instance terms in order to register on it.`
132 }
133 }
134
135 export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = {
136 VALIDATORS: [
137 Validators.minLength(3),
138 Validators.maxLength(250)
139 ],
140 MESSAGES: {
141 'minlength': $localize`Ban reason must be at least 3 characters long.`,
142 'maxlength': $localize`Ban reason cannot be more than 250 characters long.`
143 }
144 }
145
146 function buildDisplayNameValidator (required: boolean) {
147 const control = {
148 VALIDATORS: [
149 Validators.minLength(1),
150 Validators.maxLength(120)
151 ],
152 MESSAGES: {
153 'required': $localize`Display name is required.`,
154 'minlength': $localize`Display name must be at least 1 character long.`,
155 'maxlength': $localize`Display name cannot be more than 50 characters long.`
156 }
157 }
158
159 if (required) control.VALIDATORS.push(Validators.required)
160
161 return control
162 }