1
0
Fork 0
peertube/client/angular/users/components/login/login.component.ts

37 lines
1.1 KiB
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 } from '../../services/auth.service';
import { AuthStatus } from '../../models/authStatus';
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 => {
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
);
}
}