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 if (err.message === 'invalid_grant') {
61 this.error = 'Credentials are invalid.'
63 this.error = `${err.body.error_description}`