]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/form-validators/user-validators.ts
Support two factor authentication in backend
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / form-validators / user-validators.ts
CommitLineData
7ed1edbb
C
1import { Validators } from '@angular/forms'
2import { BuildFormValidator } from './form-validator.model'
3
012580d9
C
4export const USER_USERNAME_REGEX_CHARACTERS = '[a-z0-9][a-z0-9._]'
5
7ed1edbb
C
6export const USER_USERNAME_VALIDATOR: BuildFormValidator = {
7 VALIDATORS: [
8 Validators.required,
9 Validators.minLength(1),
10 Validators.maxLength(50),
012580d9 11 Validators.pattern(new RegExp(`^${USER_USERNAME_REGEX_CHARACTERS}*$`))
7ed1edbb
C
12 ],
13 MESSAGES: {
9df52d66
C
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.`
7ed1edbb
C
18 }
19}
20
21export 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: {
9df52d66
C
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.`
7ed1edbb
C
33 }
34}
35
36export const USER_EMAIL_VALIDATOR: BuildFormValidator = {
37 VALIDATORS: [ Validators.required, Validators.email ],
38 MESSAGES: {
9df52d66
C
39 required: $localize`Email is required.`,
40 email: $localize`Email must be valid.`
7ed1edbb
C
41 }
42}
43
d43c6b1f
C
44export const USER_HANDLE_VALIDATOR: BuildFormValidator = {
45 VALIDATORS: [
46 Validators.required,
47 Validators.pattern(/@.+/)
48 ],
49 MESSAGES: {
9df52d66
C
50 required: $localize`Handle is required.`,
51 pattern: $localize`Handle must be valid (eg. chocobozzz@example.com).`
d43c6b1f
C
52 }
53}
54
f8b530e0
RK
55export const USER_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = {
56 VALIDATORS: [
57 Validators.required
58 ],
59 MESSAGES: {
9df52d66 60 required: $localize`Password is required.`
f8b530e0
RK
61 }
62}
63
6f03f944 64export const USER_PASSWORD_VALIDATOR = {
7ed1edbb
C
65 VALIDATORS: [
66 Validators.required,
67 Validators.minLength(6),
68 Validators.maxLength(255)
69 ],
70 MESSAGES: {
9df52d66
C
71 required: $localize`Password is required.`,
72 minlength: $localize`Password must be at least 6 characters long.`,
73 maxlength: $localize`Password cannot be more than 255 characters long.`
7ed1edbb
C
74 }
75}
76
77export const USER_PASSWORD_OPTIONAL_VALIDATOR: BuildFormValidator = {
78 VALIDATORS: [
79 Validators.minLength(6),
80 Validators.maxLength(255)
81 ],
82 MESSAGES: {
9df52d66
C
83 minlength: $localize`Password must be at least 6 characters long.`,
84 maxlength: $localize`Password cannot be more than 255 characters long.`
7ed1edbb
C
85 }
86}
87
88export const USER_CONFIRM_PASSWORD_VALIDATOR: BuildFormValidator = {
89 VALIDATORS: [],
90 MESSAGES: {
9df52d66 91 matchPassword: $localize`The new password and the confirmed password do not correspond.`
7ed1edbb
C
92 }
93}
94
95export const USER_VIDEO_QUOTA_VALIDATOR: BuildFormValidator = {
96 VALIDATORS: [ Validators.required, Validators.min(-1) ],
97 MESSAGES: {
9df52d66
C
98 required: $localize`Video quota is required.`,
99 min: $localize`Quota must be greater than -1.`
7ed1edbb
C
100 }
101}
102export const USER_VIDEO_QUOTA_DAILY_VALIDATOR: BuildFormValidator = {
103 VALIDATORS: [ Validators.required, Validators.min(-1) ],
104 MESSAGES: {
9df52d66
C
105 required: $localize`Daily upload limit is required.`,
106 min: $localize`Daily upload limit must be greater than -1.`
7ed1edbb
C
107 }
108}
109
110export const USER_ROLE_VALIDATOR: BuildFormValidator = {
111 VALIDATORS: [ Validators.required ],
112 MESSAGES: {
9df52d66 113 required: $localize`User role is required.`
7ed1edbb
C
114 }
115}
116
117export const USER_DISPLAY_NAME_REQUIRED_VALIDATOR = buildDisplayNameValidator(true)
118
119export const USER_DESCRIPTION_VALIDATOR: BuildFormValidator = {
120 VALIDATORS: [
121 Validators.minLength(3),
122 Validators.maxLength(1000)
123 ],
124 MESSAGES: {
9df52d66
C
125 minlength: $localize`Description must be at least 3 characters long.`,
126 maxlength: $localize`Description cannot be more than 1000 characters long.`
7ed1edbb
C
127 }
128}
129
130export const USER_TERMS_VALIDATOR: BuildFormValidator = {
40360c17 131 VALIDATORS: [ Validators.requiredTrue ],
7ed1edbb 132 MESSAGES: {
9df52d66 133 required: $localize`You must agree with the instance terms in order to register on it.`
7ed1edbb
C
134 }
135}
136
137export const USER_BAN_REASON_VALIDATOR: BuildFormValidator = {
138 VALIDATORS: [
139 Validators.minLength(3),
140 Validators.maxLength(250)
141 ],
142 MESSAGES: {
9df52d66
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.`
7ed1edbb
C
145 }
146}
147
148function buildDisplayNameValidator (required: boolean) {
149 const control = {
150 VALIDATORS: [
151 Validators.minLength(1),
152 Validators.maxLength(120)
153 ],
154 MESSAGES: {
9df52d66
C
155 required: $localize`Display name is required.`,
156 minlength: $localize`Display name must be at least 1 character long.`,
157 maxlength: $localize`Display name cannot be more than 50 characters long.`
7ed1edbb
C
158 }
159 }
160
161 if (required) control.VALIDATORS.push(Validators.required)
162
163 return control
164}