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