1
0
Fork 0
peertube/client/app/users/login/login.component.ts

35 lines
974 B
TypeScript
Raw Normal View History

2016-05-13 08:18:37 -04:00
import { Component } from '@angular/core';
import { Router } from '@angular/router-deprecated';
2016-03-22 10:51:54 -04:00
import { AuthService, AuthStatus, User } from '../shared/index';
2016-03-22 10:51:54 -04:00
@Component({
selector: 'my-user-login',
styleUrls: [ 'client/app/users/login/login.component.css' ],
templateUrl: 'client/app/users/login/login.component.html'
2016-03-22 10:51:54 -04:00
})
export class UserLoginComponent {
constructor(private _authService: AuthService, private _router: Router) {}
login(username: string, password: string) {
this._authService.login(username, password).subscribe(
result => {
const user = new User(username, result);
user.save();
2016-03-22 10:51:54 -04:00
this._authService.setStatus(AuthStatus.LoggedIn);
this._router.navigate(['VideosList']);
},
error => {
if (error.error === 'invalid_grant') {
alert('Credentials are invalid.');
2016-04-14 16:12:03 -04:00
} else {
alert(`${error.error}: ${error.error_description}`);
}
}
2016-03-22 10:51:54 -04:00
);
}
}