aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/form-validators/video-change-ownership-validators.service.ts
blob: 59659defdb33e62aa4e06f40b8f87d0720896f1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { I18n } from '@ngx-translate/i18n-polyfill'
import { AbstractControl, ValidationErrors, Validators } from '@angular/forms'
import { Injectable } from '@angular/core'
import { BuildFormValidator } from './form-validator.service'

@Injectable()
export class VideoChangeOwnershipValidatorsService {
  readonly USERNAME: BuildFormValidator

  constructor (private i18n: I18n) {
    this.USERNAME = {
      VALIDATORS: [ Validators.required, this.localAccountValidator ],
      MESSAGES: {
        'required': this.i18n('The username is required.'),
        'localAccountOnly': this.i18n('You can only transfer ownership to a local account')
      }
    }
  }

  localAccountValidator (control: AbstractControl): ValidationErrors {
    if (control.value.includes('@')) {
      return { 'localAccountOnly': true }
    }

    return null
  }
}