blob: 971d57ce8bd76011b929065e6e3fb643a4bca0d2 (
plain)
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
|
import { Component, Output, OnInit, EventEmitter } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { UserService } from '../user-service/user.service';
import { ActivatedRoute } from '@angular/router';
export type LoginMessage = 'nologin' | 'invalidlogin' | string;
export class LoginEvent {
username: string;
password: string;
}
@Component({
selector: 'app-user-login',
templateUrl: './user-login.component.html',
styleUrls: ['./user-login.component.css']
})
export class UserLoginComponent implements OnInit {
constructor(private route: ActivatedRoute, private userService: UserService) { }
message: string;
form = new FormGroup({
username: new FormControl(''),
password: new FormControl('')
});
ngOnInit() {
this.message = this.route.snapshot.paramMap.get('reason');
}
onLoginButtonClick() {
this.userService.tryLogin(this.form.value).subscribe(_ => {
this.userService.userRouteNavigate(['success', { reason: 'login' }]);
}, (error: Error) => this.message = error.message);
}
}
|