1 import { Component, OnInit } from '@angular/core';
2 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3 import { Router } from '@angular/router';
5 import { AuthService } from '../core';
6 import { FormReactive } from '../shared';
10 templateUrl: './login.component.html'
13 export class LoginComponent extends FormReactive implements OnInit {
21 validationMessages = {
23 'required': 'Username is required.',
26 'required': 'Password is required.'
31 private authService: AuthService,
32 private formBuilder: FormBuilder,
33 private router: Router
39 this.form = this.formBuilder.group({
40 username: [ '', Validators.required ],
41 password: [ '', Validators.required ],
44 this.form.valueChanges.subscribe(data => this.onValueChanged(data));
54 const { username, password } = this.form.value;
56 this.authService.login(username, password).subscribe(
57 result => this.router.navigate(['/videos/list']),
60 console.error(error.json);
62 if (error.json.error === 'invalid_grant') {
63 this.error = 'Credentials are invalid.';
65 this.error = `${error.json.error}: ${error.json.error_description}`;