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 } from '../../services/auth.service';
|
|
|
|
import { AuthStatus } from '../../models/authStatus';
|
2016-04-14 16:07:46 -04:00
|
|
|
import { User } from '../../models/user';
|
2016-03-22 10:51:54 -04:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-user-login',
|
|
|
|
styleUrls: [ 'app/angular/users/components/login/login.component.css' ],
|
|
|
|
templateUrl: 'app/angular/users/components/login/login.component.html'
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|