]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/forms/form-validators/user-validators.service.ts
Add blacklist reason field
[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
11 readonly USER_VIDEO_QUOTA: BuildFormValidator
12 readonly USER_ROLE: BuildFormValidator
13 readonly USER_DISPLAY_NAME: BuildFormValidator
14 readonly USER_DESCRIPTION: BuildFormValidator
b4a929ac 15 readonly USER_TERMS: BuildFormValidator
e309822b 16
141b177d
C
17 readonly USER_BAN_REASON: BuildFormValidator
18
e309822b
C
19 constructor (private i18n: I18n) {
20
21 this.USER_USERNAME = {
22 VALIDATORS: [
23 Validators.required,
24 Validators.minLength(3),
25 Validators.maxLength(20),
26 Validators.pattern(/^[a-z0-9._]+$/)
27 ],
28 MESSAGES: {
29 'required': this.i18n('Username is required.'),
30 'minlength': this.i18n('Username must be at least 3 characters long.'),
31 'maxlength': this.i18n('Username cannot be more than 20 characters long.'),
32 'pattern': this.i18n('Username should be only lowercase alphanumeric characters.')
33 }
34 }
35
36 this.USER_EMAIL = {
37 VALIDATORS: [ Validators.required, Validators.email ],
38 MESSAGES: {
39 'required': this.i18n('Email is required.'),
40 'email': this.i18n('Email must be valid.')
41 }
42 }
43
44 this.USER_PASSWORD = {
45 VALIDATORS: [
46 Validators.required,
47 Validators.minLength(6),
48 Validators.maxLength(255)
49 ],
50 MESSAGES: {
51 'required': this.i18n('Password is required.'),
52 'minlength': this.i18n('Password must be at least 6 characters long.'),
53 'maxlength': this.i18n('Password cannot be more than 255 characters long.')
54 }
55 }
56
57 this.USER_VIDEO_QUOTA = {
58 VALIDATORS: [ Validators.required, Validators.min(-1) ],
59 MESSAGES: {
60 'required': this.i18n('Video quota is required.'),
61 'min': this.i18n('Quota must be greater than -1.')
62 }
63 }
64
65 this.USER_ROLE = {
66 VALIDATORS: [ Validators.required ],
67 MESSAGES: {
68 'required': this.i18n('User role is required.')
69 }
70 }
71
72 this.USER_DISPLAY_NAME = {
73 VALIDATORS: [
74 Validators.required,
75 Validators.minLength(3),
76 Validators.maxLength(120)
77 ],
78 MESSAGES: {
79 'required': this.i18n('Display name is required.'),
80 'minlength': this.i18n('Display name must be at least 3 characters long.'),
81 'maxlength': this.i18n('Display name cannot be more than 120 characters long.')
82 }
83 }
84
85 this.USER_DESCRIPTION = {
86 VALIDATORS: [
87 Validators.minLength(3),
88 Validators.maxLength(250)
89 ],
90 MESSAGES: {
91 'minlength': this.i18n('Description must be at least 3 characters long.'),
92 'maxlength': this.i18n('Description cannot be more than 250 characters long.')
93 }
94 }
b4a929ac
C
95
96 this.USER_TERMS = {
97 VALIDATORS: [
98 Validators.requiredTrue
99 ],
100 MESSAGES: {
101 'required': this.i18n('You must to agree with the instance terms in order to registering on it.')
102 }
103 }
141b177d
C
104
105 this.USER_BAN_REASON = {
106 VALIDATORS: [
107 Validators.minLength(3),
108 Validators.maxLength(250)
109 ],
110 MESSAGES: {
111 'minlength': this.i18n('Ban reason must be at least 3 characters long.'),
112 'maxlength': this.i18n('Ban reason cannot be more than 250 characters long.')
113 }
114 }
e309822b
C
115 }
116}