PeerTube/client/app/users/login/login.component.ts

35 lines
974 B
TypeScript
Raw Normal View History

2016-05-13 12:18:37 +00:00
import { Component } from '@angular/core';
import { Router } from '@angular/router-deprecated';
2016-03-22 14:51:54 +00:00
import { AuthService, AuthStatus, User } from '../shared/index';
2016-03-22 14:51:54 +00: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 14:51:54 +00: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 14:51:54 +00:00
this._authService.setStatus(AuthStatus.LoggedIn);
this._router.navigate(['VideosList']);
},
error => {
if (error.error === 'invalid_grant') {
alert('Credentials are invalid.');
2016-04-14 20:12:03 +00:00
} else {
alert(`${error.error}: ${error.error_description}`);
}
}
2016-03-22 14:51:54 +00:00
);
}
}