This commit is contained in:
2023-10-12 21:18:03 +07:00
parent e7678c0e5e
commit 36efa12651
24 changed files with 378 additions and 256 deletions

View File

@@ -1,7 +1,7 @@
<div class="auth">
<div class="auth-wrap">
<div class="auth-logo">
<img src="./assets/images/logo-b.png" />
<img class="logo-auth" src="./assets/images/logo-b.png" />
</div>
<div class="auth-card">
@@ -9,10 +9,10 @@
<form #ngf="ngForm" (ngSubmit)="onSubmit(ngf)">
<div class="auth-card-body">
<mat-form-field>
<input matInput type="text" name="username" [(ngModel)]="dataForm.username" #username="ngModel"
<input matInput type="text" name="loginname" [(ngModel)]="dataForm.loginname" #loginname="ngModel"
placeholder="Username" required>
<i matSuffix class="bi bi-person-circle"></i>
<mat-error *ngIf="isFieldValid(ngf, username)">กรุณากรอกข้อมูล</mat-error>
<mat-error *ngIf="isFieldValid(ngf, loginname)">กรุณากรอกข้อมูล</mat-error>
</mat-form-field>
<div style="height: 10px;"></div>
<mat-form-field>

View File

@@ -1,9 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AppService } from '../../app.service';
import { lastValueFrom } from "rxjs";
import { EAction, EText } from "../../@config/app";
import { environment } from "../../../environments/environment";
import { AuthService } from 'src/app/core/service/auth/auth.service';
import { catchError, lastValueFrom, tap, throwError } from 'rxjs';
import { EAction, EText } from 'src/app/@config/app';
@Component({
@@ -19,7 +20,8 @@ export class LoginComponent implements OnInit {
constructor(
private router: Router,
private appService: AppService,
private route: ActivatedRoute
private route: ActivatedRoute,
private authService: AuthService
) {
}
@@ -28,30 +30,19 @@ export class LoginComponent implements OnInit {
if (!environment.production) {
this.dataForm = {
username: 'admin',
password: 'password@1',
password: 'admin',
}
}
}
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);
await lastValueFrom(this.authService.login(this.dataForm));
return this.router.navigate(['/pages']);
} catch (err) {
return this.appService.message(EAction.ERROR, EText.NO_DATA);
}
}