diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-05 10:58:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-05 10:58:45 +0200 |
commit | d18d64787b3ea174f7dc2740c8c8c9555625047e (patch) | |
tree | e65089e0ca81117c1ada981b9b8a524afa8d70f5 /client/src/app/login | |
parent | 25acef90a85c1584880dec96aa402f896af8364a (diff) | |
download | PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.tar.gz PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.tar.zst PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.zip |
Form validators refractoring
Diffstat (limited to 'client/src/app/login')
-rw-r--r-- | client/src/app/login/login.component.ts | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts index a14cb2eb7..f7aad06e8 100644 --- a/client/src/app/login/login.component.ts +++ b/client/src/app/login/login.component.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' | 1 | import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' |
2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms' | ||
3 | import { Router } from '@angular/router' | ||
4 | import { RedirectService, ServerService } from '@app/core' | 2 | import { RedirectService, ServerService } from '@app/core' |
5 | import { UserService } from '@app/shared' | 3 | import { UserService } from '@app/shared' |
6 | import { NotificationsService } from 'angular2-notifications' | 4 | import { NotificationsService } from 'angular2-notifications' |
@@ -8,6 +6,8 @@ import { ModalDirective } from 'ngx-bootstrap/modal' | |||
8 | import { AuthService } from '../core' | 6 | import { AuthService } from '../core' |
9 | import { FormReactive } from '../shared' | 7 | import { FormReactive } from '../shared' |
10 | import { I18n } from '@ngx-translate/i18n-polyfill' | 8 | import { I18n } from '@ngx-translate/i18n-polyfill' |
9 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
10 | import { LOGIN_PASSWORD, LOGIN_USERNAME } from '@app/shared/forms/form-validators/login' | ||
11 | 11 | ||
12 | @Component({ | 12 | @Component({ |
13 | selector: 'my-login', | 13 | selector: 'my-login', |
@@ -20,29 +20,15 @@ export class LoginComponent extends FormReactive implements OnInit { | |||
20 | @ViewChild('forgotPasswordEmailInput') forgotPasswordEmailInput: ElementRef | 20 | @ViewChild('forgotPasswordEmailInput') forgotPasswordEmailInput: ElementRef |
21 | 21 | ||
22 | error: string = null | 22 | error: string = null |
23 | |||
24 | form: FormGroup | ||
25 | formErrors = { | ||
26 | 'username': '', | ||
27 | 'password': '' | ||
28 | } | ||
29 | validationMessages = { | ||
30 | 'username': { | ||
31 | 'required': 'Username is required.' | ||
32 | }, | ||
33 | 'password': { | ||
34 | 'required': 'Password is required.' | ||
35 | } | ||
36 | } | ||
37 | forgotPasswordEmail = '' | 23 | forgotPasswordEmail = '' |
38 | 24 | ||
39 | constructor ( | 25 | constructor ( |
26 | protected formValidatorService: FormValidatorService, | ||
40 | private authService: AuthService, | 27 | private authService: AuthService, |
41 | private userService: UserService, | 28 | private userService: UserService, |
42 | private serverService: ServerService, | 29 | private serverService: ServerService, |
43 | private redirectService: RedirectService, | 30 | private redirectService: RedirectService, |
44 | private notificationsService: NotificationsService, | 31 | private notificationsService: NotificationsService, |
45 | private formBuilder: FormBuilder, | ||
46 | private i18n: I18n | 32 | private i18n: I18n |
47 | ) { | 33 | ) { |
48 | super() | 34 | super() |
@@ -52,17 +38,11 @@ export class LoginComponent extends FormReactive implements OnInit { | |||
52 | return this.serverService.getConfig().signup.allowed === true | 38 | return this.serverService.getConfig().signup.allowed === true |
53 | } | 39 | } |
54 | 40 | ||
55 | buildForm () { | ||
56 | this.form = this.formBuilder.group({ | ||
57 | username: [ '', Validators.required ], | ||
58 | password: [ '', Validators.required ] | ||
59 | }) | ||
60 | |||
61 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
62 | } | ||
63 | |||
64 | ngOnInit () { | 41 | ngOnInit () { |
65 | this.buildForm() | 42 | this.buildForm({ |
43 | username: LOGIN_USERNAME, | ||
44 | password: LOGIN_PASSWORD | ||
45 | }) | ||
66 | } | 46 | } |
67 | 47 | ||
68 | login () { | 48 | login () { |