[init] init version
This commit is contained in:
61
src/app/auth/login/login.component.ts
Normal file
61
src/app/auth/login/login.component.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {AppService} from '../../app.service';
|
||||
import {lastValueFrom} from "rxjs";
|
||||
import {API, EAction, EText} from "../../@config/app";
|
||||
import { environment } from "../../../environments/environment";
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
templateUrl: './login.component.html',
|
||||
styles: []
|
||||
})
|
||||
export class LoginComponent implements OnInit {
|
||||
apiUrl: string = API.login;
|
||||
dataForm: any = {};
|
||||
isLoading = false;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private appService: AppService,
|
||||
private route: ActivatedRoute
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
if (!environment.production) {
|
||||
this.dataForm = {
|
||||
username : 'admin',
|
||||
password : 'password@1',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async onSubmit(form: any) {
|
||||
if (!form.valid) return false;
|
||||
const dataForm = {
|
||||
username: this.dataForm.username,
|
||||
password: this.dataForm.password,
|
||||
userType: 'ADMIN'
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
console.log(this.apiUrl)
|
||||
const result = await lastValueFrom(this.appService.post(this.apiUrl, dataForm));
|
||||
this.appService.setAuth(result.data);
|
||||
this.appService.setToken(result.accessToken);
|
||||
return this.router.navigate(['/pages']);
|
||||
} catch (err) {
|
||||
return this.appService.message(EAction.ERROR, EText.NO_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public isFieldValid(form: any, field: any) {
|
||||
return field.errors && (field.dirty || field.touched || form.submitted);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user