-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlogin.page.ts
More file actions
78 lines (66 loc) · 2.12 KB
/
login.page.ts
File metadata and controls
78 lines (66 loc) · 2.12 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Component, OnInit } from "@angular/core";
import { UntypedFormGroup, UntypedFormBuilder, Validators } from "@angular/forms";
import { Store } from "@ngrx/store";
import { selectAuthState, selectIsLoginState, selectLoginState } from "src/app/store";
import * as AuthActions from "../../actions/auth.actions";
import { LoadingProvider } from "src/app/providers/loading";
import { AuthState } from "../../store/auth.store";
import { environment } from "../../../../../environments/environment";
import { Observable } from "rxjs";
@Component({
selector: "app-login",
templateUrl: "./login.page.html",
styleUrls: ["./login.page.scss"],
})
export class LoginPage implements OnInit {
loginForm: UntypedFormGroup;
error$ = null;
isLogging$ = false;
year: number = new Date().getFullYear();
public version: string;
public authState$: Observable<AuthState | null>;
constructor(
private fb: UntypedFormBuilder,
private store: Store<AuthState>,
) {
this.authState$ = this.store.select(selectAuthState);
}
// convenience getter for easy access to form fields
get f() {
return this.loginForm.controls;
}
ngOnInit() {
this.version = environment.version;
document.body.removeAttribute("data-layout");
document.body.classList.add("auth-body-bg");
this.store.select(selectIsLoginState).subscribe((res) => {
this.isLogging$ = res;
});
this.loginForm = this.fb.group({
username: ["", Validators.required],
password: ["", [Validators.required]],
});
}
public currentYear() {
return new Date().getFullYear();
}
public login() {
this.store.dispatch(new AuthActions.IsLogin());
const authData = {
username: this.f.username.value.trim(),
password: this.f.password.value.trim(),
};
this.store.dispatch(new AuthActions.Login(authData));
this.store.select(selectIsLoginState).subscribe((res) => {
this.isLogging$ = res;
});
this.store.select(selectLoginState).subscribe(async (res) => {
if (res) {
this.error$ = res;
if (this.error$) {
this.isLogging$ = false;
}
}
});
}
}