]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/forms/form-validators/user-validators.service.ts
Fix missing python dependency in Dockerfile.buster (#2495)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / forms / form-validators / user-validators.service.ts
CommitLineData
e309822b
C
1import { I18n } from '@ngx-translate/i18n-polyfill'
2import { Validators } from '@angular/forms'
3import { BuildFormValidator } from '@app/shared'
4import { Injectable } from '@angular/core'
5
6@Injectable()
7export class UserValidatorsService {
8 readonly USER_USERNAME: BuildFormValidator
9 readonly USER_EMAIL: BuildFormValidator
10 readonly USER_PASSWORD: BuildFormValidator
b0ee41df 11 readonly USER_CONFIRM_PASSWORD: BuildFormValidator
e309822b 12 readonly USER_VIDEO_QUOTA: BuildFormValidator
bee0abff 13 readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator
e309822b 14 readonly USER_ROLE: BuildFormValidator
1f20622f 15 readonly USER_DISPLAY_NAME_REQUIRED: BuildFormValidator
e309822b 16 readonly USER_DESCRIPTION: BuildFormValidator
b4a929ac 17 readonly USER_TERMS: BuildFormValidator
e309822b 18
141b177d
C
19 readonly USER_BAN_REASON: BuildFormValidator
20
e309822b
C
21 constructor (private i18n: I18n) {
22
23 this.USER_USERNAME = {
24 VALIDATORS: [
25 Validators.required,
d0ce42c1
BY
26 Validators.minLength(1),
27 Validators.maxLength(50),
6ebfaf67 28 Validators.pattern(/^[a-z0-9][a-z0-9._]*$/)
e309822b
C
29 ],
30 MESSAGES: {
31 'required': this.i18n('Username is required.'),
d0ce42c1
BY
32 'minlength': this.i18n('Username must be at least 1 character long.'),
33 'maxlength': this.i18n('Username cannot be more than 50 characters long.'),
4523bf11 34 'pattern': this.i18n('Username should be lowercase alphanumeric; dots and underscores are allowed.')
e309822b
C
35 }
36 }
37
38 this.USER_EMAIL = {
39 VALIDATORS: [ Validators.required, Validators.email ],
40 MESSAGES: {
41 'required': this.i18n('Email is required.'),
42 'email': this.i18n('Email must be valid.')
43 }
44 }
45
46 this.USER_PASSWORD = {
47 VALIDATORS: [
48 Validators.required,
49 Validators.minLength(6),
50 Validators.maxLength(255)
51 ],
52 MESSAGES: {
53 'required': this.i18n('Password is required.'),
54 'minlength': this.i18n('Password must be at least 6 characters long.'),
55 'maxlength': this.i18n('Password cannot be more than 255 characters long.')
56 }
57 }
58
b0ee41df
C
59 this.USER_CONFIRM_PASSWORD = {
60 VALIDATORS: [],
61 MESSAGES: {
62 'matchPassword': this.i18n('The new password and the confirmed password do not correspond.')
63 }
64 }
65
e309822b
C
66 this.USER_VIDEO_QUOTA = {
67 VALIDATORS: [ Validators.required, Validators.min(-1) ],
68 MESSAGES: {
69 'required': this.i18n('Video quota is required.'),
70 'min': this.i18n('Quota must be greater than -1.')
71 }
72 }
bee0abff
FA
73 this.USER_VIDEO_QUOTA_DAILY = {
74 VALIDATORS: [ Validators.required, Validators.min(-1) ],
75 MESSAGES: {
76 'required': this.i18n('Daily upload limit is required.'),
77 'min': this.i18n('Daily upload limit must be greater than -1.')
78 }
79 }
e309822b
C
80
81 this.USER_ROLE = {
82 VALIDATORS: [ Validators.required ],
83 MESSAGES: {
84 'required': this.i18n('User role is required.')
85 }
86 }
87
1f20622f 88 this.USER_DISPLAY_NAME_REQUIRED = this.getDisplayName(true)
e309822b
C
89
90 this.USER_DESCRIPTION = {
91 VALIDATORS: [
92 Validators.minLength(3),
d23e6a1c 93 Validators.maxLength(1000)
e309822b
C
94 ],
95 MESSAGES: {
96 'minlength': this.i18n('Description must be at least 3 characters long.'),
d23e6a1c 97 'maxlength': this.i18n('Description cannot be more than 1000 characters long.')
e309822b
C
98 }
99 }
b4a929ac
C
100
101 this.USER_TERMS = {
102 VALIDATORS: [
103 Validators.requiredTrue
104 ],
105 MESSAGES: {
32d7f2b7 106 'required': this.i18n('You must agree with the instance terms in order to register on it.')
b4a929ac
C
107 }
108 }
141b177d
C
109
110 this.USER_BAN_REASON = {
111 VALIDATORS: [
112 Validators.minLength(3),
113 Validators.maxLength(250)
114 ],
115 MESSAGES: {
116 'minlength': this.i18n('Ban reason must be at least 3 characters long.'),
117 'maxlength': this.i18n('Ban reason cannot be more than 250 characters long.')
118 }
119 }
e309822b 120 }
1f20622f
C
121
122 private getDisplayName (required: boolean) {
123 const control = {
124 VALIDATORS: [
125 Validators.minLength(1),
126 Validators.maxLength(120)
127 ],
128 MESSAGES: {
129 'required': this.i18n('Display name is required.'),
130 'minlength': this.i18n('Display name must be at least 1 character long.'),
131 'maxlength': this.i18n('Display name cannot be more than 50 characters long.')
132 }
133 }
134
135 if (required) control.VALIDATORS.push(Validators.required)
136
137 return control
138 }
e309822b 139}