login.component.ts
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {TranslatePipe} from '@ngx-translate/core';
import {SessionServiceService} from '../../../shared/services/session-service.service';
import {FormGroup, NgForm} from "@angular/forms";
@Component({
selector: 'moya-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
providers: [TranslatePipe]
})
export class LoginComponent implements OnInit {
@Output()
loginEvent = new EventEmitter<boolean>();
loginError = false;
loginOk = false;
submitting = false;
constructor(private sessionService: SessionServiceService) { }
ngOnInit() {
this.loginError = this.loginOk = this.submitting = false;
}
login(userDetails: NgForm) {
this.loginError = this.loginOk = false;
this.submitting = true;
this.sessionService.doLogin(userDetails.value.username, userDetails.value.password).subscribe((x) => {
this.loginError = this.loginOk = this.submitting = false;
this.loginOk = true;
this.loginEvent.emit(true);
}, (error) => {
this.loginError = this.loginOk = this.submitting = false;
this.loginError = true;
this.loginEvent.emit(false);
});
}
}