[update] - fix login
This commit is contained in:
@@ -1,96 +1,96 @@
|
||||
|
||||
export interface MENU {
|
||||
link?: string;
|
||||
type: | 'link' | 'heading' | 'collapsable';
|
||||
icon?: string;
|
||||
name?: string;
|
||||
params?: any[];
|
||||
badge?: string;
|
||||
roles?: any[];
|
||||
children?: any[];
|
||||
permission?: string;
|
||||
collapsed?: boolean;
|
||||
notShowing?: boolean;
|
||||
isChecked?: boolean;
|
||||
link?: string;
|
||||
type: | 'link' | 'heading' | 'collapsable';
|
||||
icon?: string;
|
||||
name?: string;
|
||||
params?: any[];
|
||||
badge?: string;
|
||||
roles?: any[];
|
||||
children?: any[];
|
||||
permission?: string;
|
||||
collapsed?: boolean;
|
||||
notShowing?: boolean;
|
||||
isChecked?: boolean;
|
||||
}
|
||||
|
||||
export const ROLE_ADMIN = 'admin'
|
||||
export const ROLE_ADMIN = 'admin'
|
||||
export const NOT_ADMIN = 'not-admin'
|
||||
export const MENU: MENU[] = [
|
||||
{
|
||||
name: 'Manage',
|
||||
link: 'manage',
|
||||
permission: 'manage',
|
||||
icon: 'bi bi-card-checklist',
|
||||
{
|
||||
name: 'Manage',
|
||||
link: 'manage',
|
||||
permission: 'manage',
|
||||
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: [],
|
||||
badge: '',
|
||||
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: '',
|
||||
type: 'collapsable',
|
||||
children: [
|
||||
{
|
||||
name: 'KYC',
|
||||
link: 'manage/kyc',
|
||||
permission: 'manage-kyc',
|
||||
type: 'link',
|
||||
icon: '',
|
||||
params: [],
|
||||
badge: '',
|
||||
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: '',
|
||||
roles: [],
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'Setting',
|
||||
link: 'setting',
|
||||
permission: 'setting',
|
||||
icon: 'bi bi-gear-fill',
|
||||
params: [],
|
||||
roles: [],
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'Setting',
|
||||
link: 'setting',
|
||||
permission: 'setting',
|
||||
icon: 'bi bi-gear-fill',
|
||||
params: [],
|
||||
roles: [ROLE_ADMIN],
|
||||
badge: '',
|
||||
type: 'collapsable',
|
||||
children: [
|
||||
{
|
||||
name: 'Banner',
|
||||
link: 'setting/banner',
|
||||
permission: 'banner',
|
||||
roles: [ROLE_ADMIN],
|
||||
type: 'link',
|
||||
icon: '',
|
||||
params: [],
|
||||
badge: '',
|
||||
type: 'collapsable',
|
||||
children: [
|
||||
{
|
||||
name: 'Banner',
|
||||
link: 'setting/banner',
|
||||
permission: 'banner',
|
||||
roles: [ROLE_ADMIN],
|
||||
type: 'link',
|
||||
icon: '',
|
||||
params: [],
|
||||
badge: '',
|
||||
},
|
||||
{
|
||||
name: 'Promotion',
|
||||
link: 'setting/promotion',
|
||||
roles: [ROLE_ADMIN],
|
||||
permission: 'promotion',
|
||||
type: 'link',
|
||||
icon: '',
|
||||
params: [],
|
||||
badge: '',
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Promotion',
|
||||
link: 'setting/promotion',
|
||||
roles: [ROLE_ADMIN],
|
||||
permission: 'promotion',
|
||||
type: 'link',
|
||||
icon: '',
|
||||
params: [],
|
||||
badge: '',
|
||||
},
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,135 +4,138 @@ import { AppService } from '../../app.service';
|
||||
import { MENU, NOT_ADMIN, ROLE_ADMIN } from "../../@config/menus";
|
||||
|
||||
@Component({
|
||||
selector: 'app-pages-layouts',
|
||||
templateUrl: './layouts.component.html',
|
||||
styles: [],
|
||||
selector: 'app-pages-layouts',
|
||||
templateUrl: './layouts.component.html',
|
||||
styles: [],
|
||||
})
|
||||
export class PagesLayoutsComponent implements OnInit {
|
||||
|
||||
menus = MENU;
|
||||
isToggleSidebar = false;
|
||||
innerWidth: any;
|
||||
auth: any = {};
|
||||
isCollapsed: any = [];
|
||||
breadcrumb: any = [];
|
||||
permissionCheck = false;
|
||||
permission: any = [];
|
||||
menus = MENU;
|
||||
isToggleSidebar = false;
|
||||
innerWidth: any;
|
||||
auth: any = {};
|
||||
isCollapsed: any = [];
|
||||
breadcrumb: any = [];
|
||||
permissionCheck = false;
|
||||
permission: any = [];
|
||||
|
||||
constructor(
|
||||
private app: AppService,
|
||||
private router: Router,
|
||||
public changeDetectorRef: ChangeDetectorRef,
|
||||
) {
|
||||
constructor(
|
||||
private app: AppService,
|
||||
private router: Router,
|
||||
public changeDetectorRef: ChangeDetectorRef,
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this.onCollapsed();
|
||||
this.getBreadcrumb();
|
||||
await this.initAuth();
|
||||
this.changeDetectorRef.markForCheck()
|
||||
}
|
||||
async initAuth() {
|
||||
this.auth = this.app.auth();
|
||||
console.log(this.auth.isAdmin)
|
||||
this.menus = this.menus.map(r => {
|
||||
if(this.auth.isAdmin){
|
||||
if(r.roles.includes(ROLE_ADMIN)) return {
|
||||
...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;
|
||||
async ngOnInit() {
|
||||
this.onCollapsed();
|
||||
this.getBreadcrumb();
|
||||
await this.initAuth();
|
||||
this.changeDetectorRef.markForCheck()
|
||||
}
|
||||
async initAuth() {
|
||||
this.auth = this.app.auth();
|
||||
console.log(this.auth)
|
||||
console.log(this.auth.isAdmin)
|
||||
this.menus = this.menus.map(r => {
|
||||
if (this.auth.isAdmin) {
|
||||
if (r.roles.includes(ROLE_ADMIN)) return {
|
||||
...r,
|
||||
children: r.children.length ? r.children.filter(c => r.roles.includes(ROLE_ADMIN)) : []
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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,
|
||||
} else {
|
||||
if (r.roles.includes(NOT_ADMIN)) return {
|
||||
...r,
|
||||
children: r.children.length ? r.children.filter(c => r.roles.includes(NOT_ADMIN)) : []
|
||||
}
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.app.logout();
|
||||
return this.router.navigate(['/auth']);
|
||||
}
|
||||
logout() {
|
||||
this.app.logout();
|
||||
return this.router.navigate(['/auth']);
|
||||
}
|
||||
|
||||
|
||||
toggleSidebar() {
|
||||
this.isToggleSidebar = !this.isToggleSidebar;
|
||||
}
|
||||
toggleSidebar() {
|
||||
this.isToggleSidebar = !this.isToggleSidebar;
|
||||
}
|
||||
|
||||
closeSidebar() {
|
||||
this.isToggleSidebar = false;
|
||||
}
|
||||
closeSidebar() {
|
||||
this.isToggleSidebar = false;
|
||||
}
|
||||
|
||||
onDeactivate() {
|
||||
this.ngOnInit();
|
||||
}
|
||||
onDeactivate() {
|
||||
this.ngOnInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user