41 lines
996 B
TypeScript
41 lines
996 B
TypeScript
import {Component, OnInit, ViewChild} from '@angular/core';
|
|
import {ValidationService} from '../services/validation.service';
|
|
import {LoginService} from '../services/login.service';
|
|
import {Router} from '@angular/router';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-login',
|
|
templateUrl: './login.component.html',
|
|
styleUrls: ['./login.component.scss']
|
|
})
|
|
export class LoginComponent implements OnInit {
|
|
|
|
username = ''; // credentials
|
|
password = '';
|
|
message = ''; // message below login fields
|
|
@ViewChild('loginForm') loginForm;
|
|
|
|
|
|
constructor(
|
|
private validate: ValidationService,
|
|
private loginService: LoginService,
|
|
private router: Router
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
login() {
|
|
this.loginService.login(this.username, this.password).then(ok => {
|
|
if (ok) {
|
|
this.message = 'Login successful'; // TODO: think about following action
|
|
this.router.navigate(['/samples']);
|
|
}
|
|
else {
|
|
this.message = 'Wrong credentials!';
|
|
}
|
|
});
|
|
}
|
|
}
|