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.ts50
1 files changed, 25 insertions, 25 deletions
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts
index fd4a314cc..77703a80c 100644
--- a/client/src/app/login/login.component.ts
+++ b/client/src/app/login/login.component.ts
@@ -1,9 +1,9 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, 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 '../core'; 5import { AuthService } from '../core'
6import { FormReactive } from '../shared'; 6import { FormReactive } from '../shared'
7 7
8@Component({ 8@Component({
9 selector: 'my-login', 9 selector: 'my-login',
@@ -11,60 +11,60 @@ import { FormReactive } from '../shared';
11}) 11})
12 12
13export class LoginComponent extends FormReactive implements OnInit { 13export class LoginComponent extends FormReactive implements OnInit {
14 error: string = null; 14 error: string = null
15 15
16 form: FormGroup; 16 form: FormGroup
17 formErrors = { 17 formErrors = {
18 'username': '', 18 'username': '',
19 'password': '' 19 'password': ''
20 }; 20 }
21 validationMessages = { 21 validationMessages = {
22 'username': { 22 'username': {
23 'required': 'Username is required.', 23 'required': 'Username is required.'
24 }, 24 },
25 'password': { 25 'password': {
26 'required': 'Password is required.' 26 'required': 'Password is required.'
27 } 27 }
28 }; 28 }
29 29
30 constructor( 30 constructor (
31 private authService: AuthService, 31 private authService: AuthService,
32 private formBuilder: FormBuilder, 32 private formBuilder: FormBuilder,
33 private router: Router 33 private router: Router
34 ) { 34 ) {
35 super(); 35 super()
36 } 36 }
37 37
38 buildForm() { 38 buildForm () {
39 this.form = this.formBuilder.group({ 39 this.form = this.formBuilder.group({
40 username: [ '', Validators.required ], 40 username: [ '', Validators.required ],
41 password: [ '', Validators.required ], 41 password: [ '', Validators.required ]
42 }); 42 })
43 43
44 this.form.valueChanges.subscribe(data => this.onValueChanged(data)); 44 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
45 } 45 }
46 46
47 ngOnInit() { 47 ngOnInit () {
48 this.buildForm(); 48 this.buildForm()
49 } 49 }
50 50
51 login() { 51 login () {
52 this.error = null; 52 this.error = null
53 53
54 const { username, password } = this.form.value; 54 const { username, password } = this.form.value
55 55
56 this.authService.login(username, password).subscribe( 56 this.authService.login(username, password).subscribe(
57 result => this.router.navigate(['/videos/list']), 57 result => this.router.navigate(['/videos/list']),
58 58
59 error => { 59 error => {
60 console.error(error.json); 60 console.error(error.json)
61 61
62 if (error.json.error === 'invalid_grant') { 62 if (error.json.error === 'invalid_grant') {
63 this.error = 'Credentials are invalid.'; 63 this.error = 'Credentials are invalid.'
64 } else { 64 } else {
65 this.error = `${error.json.error}: ${error.json.error_description}`; 65 this.error = `${error.json.error}: ${error.json.error_description}`
66 } 66 }
67 } 67 }
68 ); 68 )
69 } 69 }
70} 70}