]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/login/login.component.ts
Fix favicon ratio
[github/Chocobozzz/PeerTube.git] / client / src / app / login / login.component.ts
CommitLineData
df98563e
C
1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup, Validators } from '@angular/forms'
3import { Router } from '@angular/router'
b1794c53 4
df98563e
C
5import { AuthService } from '../core'
6import { FormReactive } from '../shared'
b1794c53
C
7
8@Component({
a840d396 9 selector: 'my-login',
ec8d8440 10 templateUrl: './login.component.html'
b1794c53
C
11})
12
4b2f33f3 13export class LoginComponent extends FormReactive implements OnInit {
df98563e 14 error: string = null
4b2f33f3 15
df98563e 16 form: FormGroup
4b2f33f3
C
17 formErrors = {
18 'username': '',
19 'password': ''
df98563e 20 }
4b2f33f3
C
21 validationMessages = {
22 'username': {
df98563e 23 'required': 'Username is required.'
4b2f33f3
C
24 },
25 'password': {
26 'required': 'Password is required.'
27 }
df98563e 28 }
192ea60b 29
df98563e 30 constructor (
4fd8aa32 31 private authService: AuthService,
4b2f33f3 32 private formBuilder: FormBuilder,
4fd8aa32 33 private router: Router
4b2f33f3 34 ) {
df98563e 35 super()
4b2f33f3 36 }
b1794c53 37
df98563e 38 buildForm () {
4b2f33f3
C
39 this.form = this.formBuilder.group({
40 username: [ '', Validators.required ],
df98563e
C
41 password: [ '', Validators.required ]
42 })
4b2f33f3 43
df98563e 44 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
4b2f33f3
C
45 }
46
df98563e
C
47 ngOnInit () {
48 this.buildForm()
0f6da32b
C
49 }
50
df98563e
C
51 login () {
52 this.error = null
4b2f33f3 53
df98563e 54 const { username, password } = this.form.value
4b2f33f3
C
55
56 this.authService.login(username, password).subscribe(
57 result => this.router.navigate(['/videos/list']),
192ea60b 58
c9d6d155
C
59 err => {
60 if (err.message === 'invalid_grant') {
df98563e 61 this.error = 'Credentials are invalid.'
2e2bef6f 62 } else {
c9d6d155 63 this.error = `${err.body.error_description}`
1553e15d
C
64 }
65 }
df98563e 66 )
b1794c53
C
67 }
68}