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
|
|
|
|
2016-05-27 10:23:10 -04:00
|
|
|
import { AuthService, AuthStatus, User } from '../shared/index';
|
2016-03-22 10:51:54 -04:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-user-login',
|
2016-05-27 10:23:10 -04:00
|
|
|
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 => {
|
2016-04-14 16:07:46 -04:00
|
|
|
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']);
|
|
|
|
},
|
2016-04-14 16:07:46 -04:00
|
|
|
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-04-14 16:07:46 -04:00
|
|
|
}
|
|
|
|
}
|
2016-03-22 10:51:54 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|