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'
7 export class UserValidatorsService {
8 readonly USER_USERNAME: BuildFormValidator
9 readonly USER_EMAIL: BuildFormValidator
10 readonly USER_PASSWORD: BuildFormValidator
11 readonly USER_CONFIRM_PASSWORD: BuildFormValidator
12 readonly USER_VIDEO_QUOTA: BuildFormValidator
13 readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator
14 readonly USER_ROLE: BuildFormValidator
15 readonly USER_DISPLAY_NAME: BuildFormValidator
16 readonly USER_DESCRIPTION: BuildFormValidator
17 readonly USER_TERMS: BuildFormValidator
19 readonly USER_BAN_REASON: BuildFormValidator
21 constructor (private i18n: I18n) {
23 this.USER_USERNAME = {
26 Validators.minLength(1),
27 Validators.maxLength(50),
28 Validators.pattern(/^[a-z0-9][a-z0-9._]*$/)
31 'required': this.i18n('Username is required.'),
32 'minlength': this.i18n('Username must be at least 1 character long.'),
33 'maxlength': this.i18n('Username cannot be more than 50 characters long.'),
34 'pattern': this.i18n('Username should be lowercase alphanumeric; underscores are allowed.')
39 VALIDATORS: [ Validators.required, Validators.email ],
41 'required': this.i18n('Email is required.'),
42 'email': this.i18n('Email must be valid.')
46 this.USER_PASSWORD = {
49 Validators.minLength(6),
50 Validators.maxLength(255)
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.')
59 this.USER_CONFIRM_PASSWORD = {
62 'matchPassword': this.i18n('The new password and the confirmed password do not correspond.')
66 this.USER_VIDEO_QUOTA = {
67 VALIDATORS: [ Validators.required, Validators.min(-1) ],
69 'required': this.i18n('Video quota is required.'),
70 'min': this.i18n('Quota must be greater than -1.')
73 this.USER_VIDEO_QUOTA_DAILY = {
74 VALIDATORS: [ Validators.required, Validators.min(-1) ],
76 'required': this.i18n('Daily upload limit is required.'),
77 'min': this.i18n('Daily upload limit must be greater than -1.')
82 VALIDATORS: [ Validators.required ],
84 'required': this.i18n('User role is required.')
88 this.USER_DISPLAY_NAME = {
91 Validators.minLength(1),
92 Validators.maxLength(50)
95 'required': this.i18n('Display name is required.'),
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.')
101 this.USER_DESCRIPTION = {
103 Validators.minLength(3),
104 Validators.maxLength(1000)
107 'minlength': this.i18n('Description must be at least 3 characters long.'),
108 'maxlength': this.i18n('Description cannot be more than 1000 characters long.')
114 Validators.requiredTrue
117 'required': this.i18n('You must to agree with the instance terms in order to registering on it.')
121 this.USER_BAN_REASON = {
123 Validators.minLength(3),
124 Validators.maxLength(250)
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.')