[update] - fix login
This commit is contained in:
@@ -10,65 +10,66 @@ import { ROLE_ADMIN } from 'src/app/@config/menus';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
templateUrl: './login.component.html',
|
||||
styles: []
|
||||
selector: 'app-login',
|
||||
templateUrl: './login.component.html',
|
||||
styles: []
|
||||
})
|
||||
export class LoginComponent implements OnInit {
|
||||
dataForm: any = {};
|
||||
cathayForm: any = {
|
||||
mobileDeviceId : "1234",
|
||||
userName: 'admin',
|
||||
password: 'P@ssword1'
|
||||
};
|
||||
isLoading = false;
|
||||
dataForm: any = {};
|
||||
cathayForm: any = {
|
||||
mobileDeviceId: "1234",
|
||||
userName: 'admin',
|
||||
password: 'P@ssword1'
|
||||
};
|
||||
isLoading = false;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private appService: AppService,
|
||||
private authService: AuthService,
|
||||
private cathayAuthService: CathayAuthService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
// if (!environment.production) {
|
||||
// this.dataForm = {
|
||||
// username: 'admin',
|
||||
// password: 'admin',
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
async onSubmit(form: any) {
|
||||
if (!form.valid) return false;
|
||||
try {
|
||||
// const result = await lastValueFrom(this.authService.login(this.dataForm));
|
||||
let cathayResult: any = await lastValueFrom(this.cathayAuthService.login(this.cathayForm));
|
||||
let isAdmin = cathayResult.token.userName == ROLE_ADMIN ? true : false
|
||||
cathayResult = {
|
||||
...cathayResult,
|
||||
isAdmin: isAdmin
|
||||
}
|
||||
this.appService.setToken(cathayResult.token.token)
|
||||
this.appService.setAuth(cathayResult);
|
||||
|
||||
if(isAdmin){
|
||||
return this.router.navigate(['/pages']);
|
||||
}
|
||||
|
||||
if(!isAdmin){
|
||||
return this.router.navigate(['/pages/report/transactions']);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
return this.appService.message(EAction.ERROR, EText.NO_DATA);
|
||||
}
|
||||
constructor(
|
||||
private router: Router,
|
||||
private appService: AppService,
|
||||
private authService: AuthService,
|
||||
private cathayAuthService: CathayAuthService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
// if (!environment.production) {
|
||||
// this.dataForm = {
|
||||
// username: 'admin',
|
||||
// password: 'admin',
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
async onSubmit(form: any) {
|
||||
if (!form.valid) return false;
|
||||
try {
|
||||
// const result = await lastValueFrom(this.authService.login(this.dataForm));
|
||||
let cathayResult: any = await lastValueFrom(this.cathayAuthService.login(this.cathayForm));
|
||||
let isAdmin = cathayResult.userName == ROLE_ADMIN ? true : false
|
||||
cathayResult = {
|
||||
...cathayResult,
|
||||
isAdmin: isAdmin
|
||||
}
|
||||
|
||||
this.appService.setToken(cathayResult.token.token)
|
||||
this.appService.setAuth(cathayResult);
|
||||
|
||||
if (isAdmin) {
|
||||
return this.router.navigate(['/pages']);
|
||||
}
|
||||
|
||||
if (!isAdmin) {
|
||||
return this.router.navigate(['/pages/report/transactions']);
|
||||
}
|
||||
|
||||
} 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);
|
||||
}
|
||||
public isFieldValid(form: any, field: any) {
|
||||
return field.errors && (field.dirty || field.touched || form.submitted);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user