[update] - fix login

This commit is contained in:
2024-08-13 14:35:35 +07:00
parent 199b1975b4
commit 288beac65d
6 changed files with 4803 additions and 4767 deletions

35
package-lock.json generated
View File

@@ -21,6 +21,7 @@
"@ng-select/ng-select": "^10.0.3", "@ng-select/ng-select": "^10.0.3",
"bootstrap-icons": "^1.10.3", "bootstrap-icons": "^1.10.3",
"date-fns": "^2.29.3", "date-fns": "^2.29.3",
"f": "^1.4.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"sweetalert2": "^11.7.3", "sweetalert2": "^11.7.3",
"tslib": "^2.3.0", "tslib": "^2.3.0",
@@ -6451,6 +6452,11 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/f": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/f/-/f-1.4.0.tgz",
"integrity": "sha512-THMsoTpFuIFoQ538jpbW7x/9pVaE0jdKN2O+nd7xpeUT17lECGX8M+QOaZ186ipc3XSzSFOytaXFidItHix44Q=="
},
"node_modules/fast-deep-equal": { "node_modules/fast-deep-equal": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -15357,8 +15363,7 @@
"version": "15.2.2", "version": "15.2.2",
"resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-15.2.2.tgz", "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-15.2.2.tgz",
"integrity": "sha512-xHd5CC0Wi0a/CKfKoOC4Bwb1FVjy0esj22eQAkVh0iDKeiAQH4UG/VRmsdSHvto1z0IzGbMSt4hRbv4h2aYIdw==", "integrity": "sha512-xHd5CC0Wi0a/CKfKoOC4Bwb1FVjy0esj22eQAkVh0iDKeiAQH4UG/VRmsdSHvto1z0IzGbMSt4hRbv4h2aYIdw==",
"dev": true, "dev": true
"requires": {}
}, },
"@nodelib/fs.scandir": { "@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
@@ -15957,8 +15962,7 @@
"version": "1.8.0", "version": "1.8.0",
"resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz", "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz",
"integrity": "sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw==", "integrity": "sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw==",
"dev": true, "dev": true
"requires": {}
}, },
"acorn-node": { "acorn-node": {
"version": "1.8.2", "version": "1.8.2",
@@ -17549,6 +17553,11 @@
"tmp": "^0.0.33" "tmp": "^0.0.33"
} }
}, },
"f": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/f/-/f-1.4.0.tgz",
"integrity": "sha512-THMsoTpFuIFoQ538jpbW7x/9pVaE0jdKN2O+nd7xpeUT17lECGX8M+QOaZ186ipc3XSzSFOytaXFidItHix44Q=="
},
"fast-deep-equal": { "fast-deep-equal": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -18086,8 +18095,7 @@
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz", "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz",
"integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==", "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==",
"dev": true, "dev": true
"requires": {}
}, },
"ieee754": { "ieee754": {
"version": "1.2.1", "version": "1.2.1",
@@ -18763,8 +18771,7 @@
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/karma-jasmine-html-reporter/-/karma-jasmine-html-reporter-2.0.0.tgz", "resolved": "https://registry.npmjs.org/karma-jasmine-html-reporter/-/karma-jasmine-html-reporter-2.0.0.tgz",
"integrity": "sha512-SB8HNNiazAHXM1vGEzf8/tSyEhkfxuDdhYdPBX2Mwgzt0OuF2gicApQ+uvXLID/gXyJQgvrM9+1/2SxZFUUDIA==", "integrity": "sha512-SB8HNNiazAHXM1vGEzf8/tSyEhkfxuDdhYdPBX2Mwgzt0OuF2gicApQ+uvXLID/gXyJQgvrM9+1/2SxZFUUDIA==",
"dev": true, "dev": true
"requires": {}
}, },
"karma-source-map-support": { "karma-source-map-support": {
"version": "1.4.0", "version": "1.4.0",
@@ -20260,8 +20267,7 @@
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.0.0.tgz", "resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.0.0.tgz",
"integrity": "sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==", "integrity": "sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==",
"dev": true, "dev": true
"requires": {}
}, },
"postcss-modules-local-by-default": { "postcss-modules-local-by-default": {
"version": "4.0.0", "version": "4.0.0",
@@ -21515,8 +21521,7 @@
"version": "3.5.2", "version": "3.5.2",
"resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz",
"integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==",
"dev": true, "dev": true
"requires": {}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "0.4.1", "version": "0.4.1",
@@ -21943,8 +21948,7 @@
"version": "3.5.2", "version": "3.5.2",
"resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz",
"integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==",
"dev": true, "dev": true
"requires": {}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "0.4.1", "version": "0.4.1",
@@ -22143,8 +22147,7 @@
"version": "8.11.0", "version": "8.11.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
"dev": true, "dev": true
"requires": {}
}, },
"xtend": { "xtend": {
"version": "4.0.2", "version": "4.0.2",

View File

@@ -23,6 +23,7 @@
"@ng-select/ng-select": "^10.0.3", "@ng-select/ng-select": "^10.0.3",
"bootstrap-icons": "^1.10.3", "bootstrap-icons": "^1.10.3",
"date-fns": "^2.29.3", "date-fns": "^2.29.3",
"f": "^1.4.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"sweetalert2": "^11.7.3", "sweetalert2": "^11.7.3",
"tslib": "^2.3.0", "tslib": "^2.3.0",

View File

@@ -1,96 +1,96 @@
export interface MENU { export interface MENU {
link?: string; link?: string;
type: | 'link' | 'heading' | 'collapsable'; type: | 'link' | 'heading' | 'collapsable';
icon?: string; icon?: string;
name?: string; name?: string;
params?: any[]; params?: any[];
badge?: string; badge?: string;
roles?: any[]; roles?: any[];
children?: any[]; children?: any[];
permission?: string; permission?: string;
collapsed?: boolean; collapsed?: boolean;
notShowing?: boolean; notShowing?: boolean;
isChecked?: boolean; isChecked?: boolean;
} }
export const ROLE_ADMIN = 'admin' export const ROLE_ADMIN = 'admin'
export const NOT_ADMIN = 'not-admin' export const NOT_ADMIN = 'not-admin'
export const MENU: MENU[] = [ export const MENU: MENU[] = [
{ {
name: 'Manage', name: 'Manage',
link: 'manage', link: 'manage',
permission: 'manage', permission: 'manage',
icon: 'bi bi-card-checklist', icon: 'bi bi-card-checklist',
params: [],
roles: [ROLE_ADMIN],
badge: '',
type: 'collapsable',
children: [
{
name: 'KYC',
link: 'manage/kyc',
permission: 'manage-kyc',
type: 'link',
icon: '',
params: [], params: [],
badge: '',
roles: [ROLE_ADMIN], roles: [ROLE_ADMIN],
},
]
},
{
name: 'Report',
link: 'report',
permission: 'report',
icon: 'bi bi-file-bar-graph',
params: [],
roles: [ROLE_ADMIN, NOT_ADMIN],
badge: '',
type: 'collapsable',
children: [
{
name: 'Transactions',
link: 'report/transactions',
permission: 'transactions',
type: 'link',
icon: '',
params: [ROLE_ADMIN, NOT_ADMIN],
badge: '', badge: '',
type: 'collapsable', roles: [],
children: [ },
{ ]
name: 'KYC', },
link: 'manage/kyc', {
permission: 'manage-kyc', name: 'Setting',
type: 'link', link: 'setting',
icon: '', permission: 'setting',
params: [], icon: 'bi bi-gear-fill',
badge: '', params: [],
roles: [ROLE_ADMIN], roles: [ROLE_ADMIN],
}, badge: '',
] type: 'collapsable',
}, children: [
{ {
name: 'Report', name: 'Banner',
link: 'report', link: 'setting/banner',
permission: 'report', permission: 'banner',
icon: 'bi bi-file-bar-graph',
params: [],
roles:[ROLE_ADMIN,NOT_ADMIN],
badge: '',
type: 'collapsable',
children: [
{
name: 'Transactions',
link: 'report/transactions',
permission: 'transactions',
type: 'link',
icon: '',
params: [ROLE_ADMIN,NOT_ADMIN],
badge: '',
roles: [],
},
]
},
{
name: 'Setting',
link: 'setting',
permission: 'setting',
icon: 'bi bi-gear-fill',
params: [],
roles: [ROLE_ADMIN], roles: [ROLE_ADMIN],
type: 'link',
icon: '',
params: [],
badge: '', badge: '',
type: 'collapsable', },
children: [ {
{ name: 'Promotion',
name: 'Banner', link: 'setting/promotion',
link: 'setting/banner', roles: [ROLE_ADMIN],
permission: 'banner', permission: 'promotion',
roles: [ROLE_ADMIN], type: 'link',
type: 'link', icon: '',
icon: '', params: [],
params: [], badge: '',
badge: '', },
}, ]
{ },
name: 'Promotion',
link: 'setting/promotion',
roles: [ROLE_ADMIN],
permission: 'promotion',
type: 'link',
icon: '',
params: [],
badge: '',
},
]
},
]; ];

View File

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

View File

@@ -4,135 +4,138 @@ import { AppService } from '../../app.service';
import { MENU, NOT_ADMIN, ROLE_ADMIN } from "../../@config/menus"; import { MENU, NOT_ADMIN, ROLE_ADMIN } from "../../@config/menus";
@Component({ @Component({
selector: 'app-pages-layouts', selector: 'app-pages-layouts',
templateUrl: './layouts.component.html', templateUrl: './layouts.component.html',
styles: [], styles: [],
}) })
export class PagesLayoutsComponent implements OnInit { export class PagesLayoutsComponent implements OnInit {
menus = MENU; menus = MENU;
isToggleSidebar = false; isToggleSidebar = false;
innerWidth: any; innerWidth: any;
auth: any = {}; auth: any = {};
isCollapsed: any = []; isCollapsed: any = [];
breadcrumb: any = []; breadcrumb: any = [];
permissionCheck = false; permissionCheck = false;
permission: any = []; permission: any = [];
constructor( constructor(
private app: AppService, private app: AppService,
private router: Router, private router: Router,
public changeDetectorRef: ChangeDetectorRef, public changeDetectorRef: ChangeDetectorRef,
) { ) {
} }
async ngOnInit() { async ngOnInit() {
this.onCollapsed(); this.onCollapsed();
this.getBreadcrumb(); this.getBreadcrumb();
await this.initAuth(); await this.initAuth();
this.changeDetectorRef.markForCheck() this.changeDetectorRef.markForCheck()
} }
async initAuth() { async initAuth() {
this.auth = this.app.auth(); this.auth = this.app.auth();
console.log(this.auth.isAdmin) console.log(this.auth)
this.menus = this.menus.map(r => { console.log(this.auth.isAdmin)
if(this.auth.isAdmin){ this.menus = this.menus.map(r => {
if(r.roles.includes(ROLE_ADMIN)) return { if (this.auth.isAdmin) {
...r, if (r.roles.includes(ROLE_ADMIN)) return {
children: r.children.length ? r.children.filter(c => r.roles.includes(ROLE_ADMIN)) : [] ...r,
} children: r.children.length ? r.children.filter(c => r.roles.includes(ROLE_ADMIN)) : []
} else {
if(r.roles.includes(NOT_ADMIN)) return {
...r,
children: r.children.length ? r.children.filter(c => r.roles.includes(NOT_ADMIN)) : []
}
}
})
if (!this.permissionCheck) {
// const users = await lastValueFrom(this.app.get(`${API.users}/getById/${this.auth.id}`));
// this.permission = users.permission;
// this.permissionCheck = true;
} }
} else {
} if (r.roles.includes(NOT_ADMIN)) return {
...r,
roleCheck(perm: string){ children: r.children.length ? r.children.filter(c => r.roles.includes(NOT_ADMIN)) : []
// if(!environment.production) return true
// return this.permission.includes(perm)
return true;
}
getBreadcrumb() {
this.breadcrumb = [];
let router: any = this.router.url;
router = router.split('/');
this.mapBreadcrumb(router, this.menus)
this.changeDetectorRef.markForCheck()
}
mapBreadcrumb(router: any, items: any) {
items.map((item: any) => {
this.addItemBreadcrumb(router, item);
if (item.children) this.mapBreadcrumb(router, item.children);
});
}
addItemBreadcrumb(router: any, item: any) {
const data = {
name: item.name,
link: item.link,
} }
if (router[2]) { }
if (item.link === router[2]) this.breadcrumb.push(data); })
if (!this.permissionCheck) {
// const users = await lastValueFrom(this.app.get(`${API.users}/getById/${this.auth.id}`));
// this.permission = users.permission;
// this.permissionCheck = true;
}
}
roleCheck(perm: string) {
// if(!environment.production) return true
// return this.permission.includes(perm)
return true;
}
getBreadcrumb() {
this.breadcrumb = [];
let router: any = this.router.url;
router = router.split('/');
this.mapBreadcrumb(router, this.menus)
this.changeDetectorRef.markForCheck()
}
mapBreadcrumb(router: any, items: any) {
items.map((item: any) => {
this.addItemBreadcrumb(router, item);
if (item.children) this.mapBreadcrumb(router, item.children);
});
}
addItemBreadcrumb(router: any, item: any) {
const data = {
name: item.name,
link: item.link,
}
if (router[2]) {
if (item.link === router[2]) this.breadcrumb.push(data);
}
if (router[3]) {
if (item.link === `${router[2]}/${router[3]}`) this.breadcrumb.push(data);
}
if (router[4]) {
if (item.link === `${router[2]}/${router[3]}/${router[4]}`) this.breadcrumb.push(data);
}
if (router[5]) {
if (item.link === `${router[2]}/${router[3]}/${router[4]}/${router[5]}`) this.breadcrumb.push(data);
}
if (router[6]) {
if (item.link === `${router[2]}/${router[3]}/${router[4]}/${router[5]}/${router[6]}`) this.breadcrumb.push(data);
}
}
onCollapsed() {
let router: any = this.router.url;
router = router.split('/');
this.menus.forEach((item: any, i: number) => {
// item.collapsed = false;
if (item.type === 'collapsable') {
if (router.includes(item.link)) {
item.collapsed = true;
} }
if (router[3]) { }
if (item.link === `${router[2]}/${router[3]}`) this.breadcrumb.push(data); });
} }
if (router[4]) {
if (item.link === `${router[2]}/${router[3]}/${router[4]}`) this.breadcrumb.push(data);
}
if (router[5]) {
if (item.link === `${router[2]}/${router[3]}/${router[4]}/${router[5]}`) this.breadcrumb.push(data);
}
if (router[6]) {
if (item.link === `${router[2]}/${router[3]}/${router[4]}/${router[5]}/${router[6]}`) this.breadcrumb.push(data);
}
}
onCollapsed() { logout() {
let router: any = this.router.url; this.app.logout();
router = router.split('/'); return this.router.navigate(['/auth']);
this.menus.forEach((item: any, i: number) => { }
// item.collapsed = false;
if (item.type === 'collapsable') {
if (router.includes(item.link)) {
item.collapsed = true;
}
}
});
}
logout() {
this.app.logout();
return this.router.navigate(['/auth']);
}
toggleSidebar() { toggleSidebar() {
this.isToggleSidebar = !this.isToggleSidebar; this.isToggleSidebar = !this.isToggleSidebar;
} }
closeSidebar() { closeSidebar() {
this.isToggleSidebar = false; this.isToggleSidebar = false;
} }
onDeactivate() { onDeactivate() {
this.ngOnInit(); this.ngOnInit();
} }
} }

9020
yarn.lock

File diff suppressed because it is too large Load Diff