opt-cc/static/src/app/login/login.component.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-05-10 11:04:06 +02:00
import {Component, OnInit} from "@angular/core";
2017-07-27 16:38:35 +02:00
import {Router} from "@angular/router";
2017-10-22 18:06:37 +02:00
import {LoginService} from "../services/app-user-service/login-service";
import {RouteConfig} from "../app.config";
2017-05-10 11:04:06 +02:00
@Component({
moduleId: module.id,
templateUrl: 'login.component.html',
styleUrls: ['login.component.css']
})
export class LoginComponent implements OnInit {
showErrorLabel = false;
2017-06-08 19:46:36 +02:00
error: string;
2017-05-10 11:04:06 +02:00
loading = false;
returnUrl: string;
2017-07-27 16:38:35 +02:00
constructor(private router: Router,
2017-05-10 11:04:06 +02:00
private loginService: LoginService) {
}
ngOnInit() {
// reset login status
this.loginService.logout();
2017-06-08 16:58:28 +02:00
// redirect on success
this.returnUrl = RouteConfig.overviewPath;
2017-05-10 11:04:06 +02:00
}
login(username: string, password: string) {
if (username.length > 0 && password.length > 0) {
this.loading = true;
this.loginService.login(username, password)
2018-02-26 09:04:27 +01:00
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
this.error = error._body;
this.showErrorLabel = true;
setTimeout(() => {
this.showErrorLabel = false;
}, 4000);
this.loading = false;
});
2017-05-10 11:04:06 +02:00
}
}
}