aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/login/login.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/login/login.component.ts')
-rw-r--r--client/src/app/login/login.component.ts53
1 files changed, 37 insertions, 16 deletions
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts
index 7a4e15c2c..378714ca1 100644
--- a/client/src/app/login/login.component.ts
+++ b/client/src/app/login/login.component.ts
@@ -1,39 +1,60 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core';
2import { FormControl, FormGroup, Validators } from '@angular/forms'; 2import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3import { Router } from '@angular/router'; 3import { Router } from '@angular/router';
4 4
5import { AuthService } from '../shared'; 5import { AuthService, FormReactive } from '../shared';
6 6
7@Component({ 7@Component({
8 selector: 'my-login', 8 selector: 'my-login',
9 template: require('./login.component.html') 9 template: require('./login.component.html')
10}) 10})
11 11
12export class LoginComponent implements OnInit { 12export class LoginComponent extends FormReactive implements OnInit {
13 error: string = null; 13 error: string = null;
14 username = ''; 14
15 password: ''; 15 form: FormGroup;
16 loginForm: FormGroup; 16 formErrors = {
17 'username': '',
18 'password': ''
19 };
20 validationMessages = {
21 'username': {
22 'required': 'Username is required.',
23 },
24 'password': {
25 'required': 'Password is required.'
26 }
27 };
17 28
18 constructor( 29 constructor(
19 private authService: AuthService, 30 private authService: AuthService,
31 private formBuilder: FormBuilder,
20 private router: Router 32 private router: Router
21 ) {} 33 ) {
34 super();
35 }
22 36
23 ngOnInit() { 37 buildForm() {
24 this.loginForm = new FormGroup({ 38 this.form = this.formBuilder.group({
25 username: new FormControl('', [ <any>Validators.required ]), 39 username: [ '', Validators.required ],
26 password: new FormControl('', [ <any>Validators.required ]), 40 password: [ '', Validators.required ],
27 }); 41 });
42
43 this.form.valueChanges.subscribe(data => this.onValueChanged(data));
44 }
45
46 ngOnInit() {
47 this.buildForm();
28 } 48 }
29 49
30 login() { 50 login() {
31 this.authService.login(this.username, this.password).subscribe( 51 this.error = null;
32 result => { 52
33 this.error = null; 53 const { username, password } = this.form.value;
54
55 this.authService.login(username, password).subscribe(
56 result => this.router.navigate(['/videos/list']),
34 57
35 this.router.navigate(['/videos/list']);
36 },
37 error => { 58 error => {
38 console.error(error.json); 59 console.error(error.json);
39 60