definma-ui/src/app/login/login.component.ts

41 lines
996 B
TypeScript
Raw Normal View History

import {Component, OnInit, ViewChild} from '@angular/core';
import {ValidationService} from '../services/validation.service';
import {LoginService} from '../services/login.service';
2020-07-13 10:52:10 +02:00
import {Router} from '@angular/router';
2020-05-19 12:49:06 +02:00
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
2020-05-20 10:07:34 +02:00
username = ''; // credentials
password = '';
message = ''; // message below login fields
@ViewChild('loginForm') loginForm;
2020-05-19 12:49:06 +02:00
2020-05-20 10:07:34 +02:00
constructor(
private validate: ValidationService,
private loginService: LoginService,
2020-07-13 10:52:10 +02:00
private router: Router
2020-05-20 10:07:34 +02:00
) { }
2020-05-19 12:49:06 +02:00
ngOnInit() {
}
2020-05-20 10:07:34 +02:00
login() {
this.loginService.login(this.username, this.password).then(ok => {
if (ok) {
this.message = 'Login successful'; // TODO: think about following action
2020-07-13 10:52:10 +02:00
this.router.navigate(['/samples']);
}
else {
this.message = 'Wrong credentials!';
}
});
2020-05-20 10:07:34 +02:00
}
2020-05-19 12:49:06 +02:00
}