blob: 836202de9b8530a4af43e0e9c03eb5a457a99912 (
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
|
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { InternalUserService } from '../internal-user-service/internal-user.service';
export type LoginMessage = 'nologin' | 'invalidlogin' | string | null | undefined;
@Component({
selector: 'app-user-login',
templateUrl: './user-login.component.html',
styleUrls: ['./user-login.component.css']
})
export class UserLoginComponent implements OnInit {
constructor(private userService: InternalUserService) { }
message: LoginMessage;
form = new FormGroup({
username: new FormControl(''),
password: new FormControl('')
});
ngOnInit() {
if (this.userService.currentUserInfo) {
throw new Error('Route error! Already login!');
}
this.message = 'nologin';
}
onLoginButtonClick() {
this.userService.tryLogin(this.form.value).subscribe(_ => {
this.userService.userRouteNavigate(['success', { fromlogin: 'true' }]);
}, (error: Error) => this.message = error.message);
}
}
|