2017-05-10 11:04:06 +02:00
|
|
|
import {Component, OnInit} from "@angular/core";
|
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {LoginService} from "../services/login-service/login-service";
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
moduleId: module.id,
|
|
|
|
templateUrl: 'login.component.html',
|
|
|
|
styleUrls: ['login.component.css']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class LoginComponent implements OnInit {
|
|
|
|
|
|
|
|
showErrorLabel = false;
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
|
|
|
|
returnUrl: string;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private loginService: LoginService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
// reset login status
|
|
|
|
this.loginService.logout();
|
2017-06-08 16:58:28 +02:00
|
|
|
// redirect on success
|
|
|
|
this.returnUrl = '/cc-overview'
|
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)
|
|
|
|
.subscribe(
|
|
|
|
data => {
|
|
|
|
this.router.navigate([this.returnUrl]);
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.showErrorLabel = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.showErrorLabel = false;
|
2017-05-18 14:45:00 +02:00
|
|
|
}, 4000);
|
2017-05-10 11:04:06 +02:00
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|