]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/form-validators/user-validators.ts
improvements to login and sign-up pages (#3357)
[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_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = {
43 VALIDATORS: [
44 Validators.required
45 ],
46 MESSAGES: {
47 'required': $localize`Password is required.`
48 }
49 }
50
51 export const USER_PASSWORD_VALIDATOR: BuildFormValidator = {
52 VALIDATORS: [
53 Validators.required,
54 Validators.minLength(6),
55 Validators.maxLength(255)
56 ],
57 MESSAGES: {
58 'required': $localize`Password is required.`,
59 'minlength': $localize`Password must be at least 6 characters long.`,
60 'maxlength': $localize`Password cannot be more than 255 characters long.`
61 }
62 }
63
64 export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = {
65 VALIDATORS: [
66 Validators.minLength(6),
67 Validators.maxLength(255)
68 ],
69 MESSAGES: {
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_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = {
76 VALIDATORS: [],
77 MESSAGES: {
78 'matchPassword': $localize`The new password and the confirmed password do not correspond.`
79 }
80 }
81
82 export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
83 VALIDATORS: [ Validators.required, Validators.min(-1) ],
84 MESSAGES: {
85 'required': $localize`Video quota is required.`,
86 'min': $localize`Quota must be greater than -1.`
87 }
88 }
89 export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = {
90 VALIDATORS: [ Validators.required, Validators.min(-1) ],
91 MESSAGES: {
92 'required': $localize`Daily upload limit is required.`,
93 'min': $localize`Daily upload limit must be greater than -1.`
94 }
95 }
96
97 export const USER_ROLE_VALIDATOR: BuildFormValidator = {
98 VALIDATORS: [ Validators.required ],
99 MESSAGES: {
100 'required': $localize`User role is required.`
101 }
102 }
103
104 export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true)
105
106 export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = {
107 VALIDATORS: [
108 Validators.minLength(3),
109 Validators.maxLength(1000)
110 ],
111 MESSAGES: {
112 'minlength': $localize`Description must be at least 3 characters long.`,
113 'maxlength': $localize`Description cannot be more than 1000 characters long.`
114 }
115 }
116
117 export const USER_TERMS_VALIDATOR: BuildFormValidator = {
118 VALIDATORS: [ Validators.requiredTrue ],
119 MESSAGES: {
120 'required': $localize`You must agree with the instance terms in order to register on it.`
121 }
122 }
123
124 export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = {
125 VALIDATORS: [
126 Validators.minLength(3),
127 Validators.maxLength(250)
128 ],
129 MESSAGES: {
130 'minlength': $localize`Ban reason must be at least 3 characters long.`,
131 'maxlength': $localize`Ban reason cannot be more than 250 characters long.`
132 }
133 }
134
135 function buildDisplayNameValidator (required: boolean) {
136 const control = {
137 VALIDATORS: [
138 Validators.minLength(1),
139 Validators.maxLength(120)
140 ],
141 MESSAGES: {
142 'required': $localize`Display name is required.`,
143 'minlength': $localize`Display name must be at least 1 character long.`,
144 'maxlength': $localize`Display name cannot be more than 50 characters long.`
145 }
146 }
147
148 if (required) control.VALIDATORS.push(Validators.required)
149
150 return control
151 }