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

48 lines
1.3 KiB
TypeScript
Raw Normal View History

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';
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',
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,
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
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 => {
// 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
}
}
}