]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/forms/form-validators/user-validators.service.ts
dots are allowed in actor names
[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
C
14 readonly USER_ROLE: BuildFormValidator
15 readonly USER_DISPLAY_NAME: BuildFormValidator
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
88 this.USER_DISPLAY_NAME = {
89 VALIDATORS: [
90 Validators.required,
d0ce42c1
BY
91 Validators.minLength(1),
92 Validators.maxLength(50)
e309822b
C
93 ],
94 MESSAGES: {
95 'required': this.i18n('Display name is required.'),
d0ce42c1
BY
96 'minlength': this.i18n('Display name must be at least 1 character long.'),
97 'maxlength': this.i18n('Display name cannot be more than 50 characters long.')
e309822b
C
98 }
99 }
100
101 this.USER_DESCRIPTION = {
102 VALIDATORS: [
103 Validators.minLength(3),
d23e6a1c 104 Validators.maxLength(1000)
e309822b
C
105 ],
106 MESSAGES: {
107 'minlength': this.i18n('Description must be at least 3 characters long.'),
d23e6a1c 108 'maxlength': this.i18n('Description cannot be more than 1000 characters long.')
e309822b
C
109 }
110 }
b4a929ac
C
111
112 this.USER_TERMS = {
113 VALIDATORS: [
114 Validators.requiredTrue
115 ],
116 MESSAGES: {
117 'required': this.i18n('You must to agree with the instance terms in order to registering on it.')
118 }
119 }
141b177d
C
120
121 this.USER_BAN_REASON = {
122 VALIDATORS: [
123 Validators.minLength(3),
124 Validators.maxLength(250)
125 ],
126 MESSAGES: {
127 'minlength': this.i18n('Ban reason must be at least 3 characters long.'),
128 'maxlength': this.i18n('Ban reason cannot be more than 250 characters long.')
129 }
130 }
e309822b
C
131 }
132}