2018-03-07 11:56:50 +01:00
|
|
|
import {Component, OnInit} from '@angular/core';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {LoginService} from '../services/app-user-service/login-service';
|
|
|
|
import {RouteConfig} from '../app.config';
|
2018-07-17 11:34:32 +02:00
|
|
|
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
moduleId: module.id,
|
|
|
|
templateUrl: 'login.component.html',
|
2019-02-25 14:32:29 +01:00
|
|
|
styleUrls: ['login.component.scss']
|
2017-05-10 11:04:06 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export class LoginComponent implements OnInit {
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
|
|
|
|
returnUrl: string;
|
|
|
|
|
2017-07-27 16:38:35 +02:00
|
|
|
constructor(private router: Router,
|
2018-07-17 11:34:32 +02:00
|
|
|
private loginService: LoginService,
|
|
|
|
private snackBarService: SnackBarService) {
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
// reset login status
|
|
|
|
this.loginService.logout();
|
2017-06-08 16:58:28 +02:00
|
|
|
// redirect on success
|
2017-08-01 23:52:10 +02:00
|
|
|
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 => {
|
2018-11-24 14:12:05 +01:00
|
|
|
// TODO: return i18n key from backend to use translate error method
|
|
|
|
this.snackBarService.showUntranslatedError(error.error, 15000);
|
2018-02-26 09:04:27 +01:00
|
|
|
this.loading = false;
|
|
|
|
});
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|