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