@brggroup/share-lib 0.0.89 → 0.0.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/brggroup-share-lib.mjs +205 -245
- package/fesm2022/brggroup-share-lib.mjs.map +1 -1
- package/lib/auth/auth.service.d.ts +0 -3
- package/lib/auth/auth.service.d.ts.map +1 -1
- package/lib/auth/session-manager.service.d.ts +6 -12
- package/lib/auth/session-manager.service.d.ts.map +1 -1
- package/lib/components/layout/layout-user/layout-user.d.ts +2 -0
- package/lib/components/layout/layout-user/layout-user.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -543,227 +543,6 @@ class TokenStorage {
|
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
class SessionManagerService {
|
|
547
|
-
zone;
|
|
548
|
-
constructor(zone) {
|
|
549
|
-
this.zone = zone;
|
|
550
|
-
}
|
|
551
|
-
handlers;
|
|
552
|
-
idleTimer;
|
|
553
|
-
refreshTimer;
|
|
554
|
-
heartbeatTimer;
|
|
555
|
-
static IDLE_MIN = 15;
|
|
556
|
-
REFRESH_BEFORE = 120;
|
|
557
|
-
get IDLE_TIME() {
|
|
558
|
-
return (SessionManagerService.IDLE_MIN || 0) * 60 * 1000;
|
|
559
|
-
}
|
|
560
|
-
LEADER_KEY = 'APP_SESSION_LEADER';
|
|
561
|
-
HEARTBEAT_KEY = 'APP_SESSION_HEARTBEAT';
|
|
562
|
-
ACTIVITY_KEY = 'APP_LAST_ACTIVITY';
|
|
563
|
-
SESSION_EVENT = 'APP_SESSION_EVENT';
|
|
564
|
-
LOGIN_EVENT = 'APP_LOGIN_EVENT';
|
|
565
|
-
LOGOUT_EVENT = 'APP_LOGOUT_EVENT';
|
|
566
|
-
ACTIVITY_EVENT = 'APP_ACTIVITY_EVENT';
|
|
567
|
-
TOKEN_REFRESH_EVENT = 'APP_TOKEN_REFRESH_EVENT';
|
|
568
|
-
tabId = crypto.randomUUID();
|
|
569
|
-
isLeader = false;
|
|
570
|
-
isRunning = false;
|
|
571
|
-
refreshLock = false;
|
|
572
|
-
channel = null;
|
|
573
|
-
/* -------------------------------- START -------------------------------- */
|
|
574
|
-
start(handlers) {
|
|
575
|
-
if (this.IDLE_TIME <= 0 || this.isRunning)
|
|
576
|
-
return;
|
|
577
|
-
this.isRunning = true;
|
|
578
|
-
this.handlers = handlers;
|
|
579
|
-
if ('BroadcastChannel' in window) {
|
|
580
|
-
this.channel = new BroadcastChannel('APP_SESSION');
|
|
581
|
-
this.listenChannel();
|
|
582
|
-
}
|
|
583
|
-
this.listenActivity();
|
|
584
|
-
this.updateActivity();
|
|
585
|
-
this.resetIdle();
|
|
586
|
-
this.electLeader();
|
|
587
|
-
}
|
|
588
|
-
// stop() {
|
|
589
|
-
// this.isRunning = false;
|
|
590
|
-
// clearTimeout(this.idleTimer);
|
|
591
|
-
// clearTimeout(this.refreshTimer);
|
|
592
|
-
// clearInterval(this.heartbeatTimer);
|
|
593
|
-
// this.channel?.close();
|
|
594
|
-
// this.channel = null;
|
|
595
|
-
// }
|
|
596
|
-
/* -------------------------------- ACTIVITY -------------------------------- */
|
|
597
|
-
listenActivity() {
|
|
598
|
-
const events = ['mousemove', 'keydown', 'click', 'scroll'];
|
|
599
|
-
events.forEach((e) => {
|
|
600
|
-
window.addEventListener(e, this.onActivity, true);
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
onActivity = this.debounce(() => {
|
|
604
|
-
if (!this.isRunning)
|
|
605
|
-
return;
|
|
606
|
-
this.updateActivity();
|
|
607
|
-
this.resetIdle();
|
|
608
|
-
this.broadcast(this.ACTIVITY_EVENT);
|
|
609
|
-
}, 1000);
|
|
610
|
-
updateActivity() {
|
|
611
|
-
localStorage.setItem(this.ACTIVITY_KEY, Date.now().toString());
|
|
612
|
-
}
|
|
613
|
-
/* -------------------------------- IDLE -------------------------------- */
|
|
614
|
-
resetIdle() {
|
|
615
|
-
if (!this.isRunning)
|
|
616
|
-
return;
|
|
617
|
-
clearTimeout(this.idleTimer);
|
|
618
|
-
const last = Number(localStorage.getItem(this.ACTIVITY_KEY) || Date.now());
|
|
619
|
-
const remain = this.IDLE_TIME - (Date.now() - last);
|
|
620
|
-
if (remain <= 0) {
|
|
621
|
-
this.logout();
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
this.zone.runOutsideAngular(() => {
|
|
625
|
-
this.idleTimer = setTimeout(() => {
|
|
626
|
-
this.zone.run(() => this.logout());
|
|
627
|
-
}, remain);
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
/* -------------------------------- LEADER -------------------------------- */
|
|
631
|
-
electLeader() {
|
|
632
|
-
const leader = localStorage.getItem(this.LEADER_KEY);
|
|
633
|
-
if (!leader) {
|
|
634
|
-
this.becomeLeader();
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
this.checkLeaderHeartbeat();
|
|
638
|
-
}
|
|
639
|
-
becomeLeader() {
|
|
640
|
-
this.isLeader = true;
|
|
641
|
-
localStorage.setItem(this.LEADER_KEY, this.tabId);
|
|
642
|
-
this.startHeartbeat();
|
|
643
|
-
this.scheduleRefresh();
|
|
644
|
-
}
|
|
645
|
-
startHeartbeat() {
|
|
646
|
-
this.heartbeatTimer = setInterval(() => {
|
|
647
|
-
localStorage.setItem(this.HEARTBEAT_KEY, Date.now().toString());
|
|
648
|
-
}, 2000);
|
|
649
|
-
}
|
|
650
|
-
checkLeaderHeartbeat() {
|
|
651
|
-
setTimeout(() => {
|
|
652
|
-
const beat = Number(localStorage.getItem(this.HEARTBEAT_KEY) || 0);
|
|
653
|
-
if (Date.now() - beat > 5000) {
|
|
654
|
-
this.becomeLeader();
|
|
655
|
-
}
|
|
656
|
-
}, 3000);
|
|
657
|
-
}
|
|
658
|
-
/* -------------------------------- REFRESH TOKEN -------------------------------- */
|
|
659
|
-
scheduleRefresh() {
|
|
660
|
-
if (!this.isLeader || !this.isRunning)
|
|
661
|
-
return;
|
|
662
|
-
clearTimeout(this.refreshTimer);
|
|
663
|
-
const token = this.handlers.getToken();
|
|
664
|
-
if (!token)
|
|
665
|
-
return;
|
|
666
|
-
const exp = this.parseJwt(token).exp * 1000;
|
|
667
|
-
const delay = exp - Date.now() - this.REFRESH_BEFORE * 1000;
|
|
668
|
-
if (delay <= 0) {
|
|
669
|
-
this.refreshToken();
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
this.refreshTimer = setTimeout(() => {
|
|
673
|
-
this.refreshToken();
|
|
674
|
-
}, delay);
|
|
675
|
-
}
|
|
676
|
-
async refreshToken() {
|
|
677
|
-
if (!this.isLeader || this.refreshLock || !this.isRunning)
|
|
678
|
-
return;
|
|
679
|
-
this.refreshLock = true;
|
|
680
|
-
try {
|
|
681
|
-
const res = await this.handlers.refreshToken();
|
|
682
|
-
if (res?.IsSuccess) {
|
|
683
|
-
this.broadcast(this.TOKEN_REFRESH_EVENT);
|
|
684
|
-
this.scheduleRefresh();
|
|
685
|
-
}
|
|
686
|
-
else {
|
|
687
|
-
this.logout();
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
catch {
|
|
691
|
-
this.logout();
|
|
692
|
-
}
|
|
693
|
-
finally {
|
|
694
|
-
this.refreshLock = false;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
/* -------------------------------- CHANNEL -------------------------------- */
|
|
698
|
-
listenChannel() {
|
|
699
|
-
if (!this.channel)
|
|
700
|
-
return;
|
|
701
|
-
this.channel.onmessage = (msg) => {
|
|
702
|
-
if (!this.isRunning)
|
|
703
|
-
return;
|
|
704
|
-
const type = msg.data?.type;
|
|
705
|
-
if (type === this.ACTIVITY_EVENT) {
|
|
706
|
-
this.resetIdle();
|
|
707
|
-
}
|
|
708
|
-
if (type === this.LOGOUT_EVENT) {
|
|
709
|
-
console.log('APP_SESSION CHANNEL: ', this.LOGOUT_EVENT);
|
|
710
|
-
this.handlers.logout();
|
|
711
|
-
}
|
|
712
|
-
if (type === this.LOGIN_EVENT) {
|
|
713
|
-
console.log('APP_SESSION CHANNEL: ', this.LOGIN_EVENT);
|
|
714
|
-
location.reload();
|
|
715
|
-
}
|
|
716
|
-
if (type === this.TOKEN_REFRESH_EVENT) {
|
|
717
|
-
console.log('APP_SESSION CHANNEL: ', this.TOKEN_REFRESH_EVENT);
|
|
718
|
-
this.scheduleRefresh();
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
broadcast(type) {
|
|
723
|
-
if (!this.isRunning)
|
|
724
|
-
return;
|
|
725
|
-
if (this.channel) {
|
|
726
|
-
this.channel.postMessage({ type });
|
|
727
|
-
}
|
|
728
|
-
else {
|
|
729
|
-
localStorage.setItem(this.SESSION_EVENT, JSON.stringify({ type, t: Date.now() }));
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
broadcastLogin() {
|
|
733
|
-
this.broadcast(this.LOGIN_EVENT);
|
|
734
|
-
}
|
|
735
|
-
broadcastLogout() {
|
|
736
|
-
this.broadcast(this.LOGOUT_EVENT);
|
|
737
|
-
}
|
|
738
|
-
/* -------------------------------- LOGOUT -------------------------------- */
|
|
739
|
-
logout() {
|
|
740
|
-
if (!this.isRunning)
|
|
741
|
-
return;
|
|
742
|
-
this.handlers.logout();
|
|
743
|
-
this.broadcast(this.LOGOUT_EVENT);
|
|
744
|
-
}
|
|
745
|
-
/* -------------------------------- UTILS -------------------------------- */
|
|
746
|
-
debounce(fn, delay) {
|
|
747
|
-
let timer;
|
|
748
|
-
return () => {
|
|
749
|
-
clearTimeout(timer);
|
|
750
|
-
timer = setTimeout(() => fn(), delay);
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
parseJwt(token) {
|
|
754
|
-
const payload = token.split('.')[1];
|
|
755
|
-
return JSON.parse(atob(payload));
|
|
756
|
-
}
|
|
757
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: SessionManagerService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
758
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: SessionManagerService, providedIn: 'root' });
|
|
759
|
-
}
|
|
760
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: SessionManagerService, decorators: [{
|
|
761
|
-
type: Injectable,
|
|
762
|
-
args: [{
|
|
763
|
-
providedIn: 'root',
|
|
764
|
-
}]
|
|
765
|
-
}], ctorParameters: () => [{ type: i0.NgZone }] });
|
|
766
|
-
|
|
767
546
|
const URLs$4 = {
|
|
768
547
|
login: '/api/Auth/Login',
|
|
769
548
|
register: '/api/Auth/Register',
|
|
@@ -777,7 +556,6 @@ class AuthService extends HTTPService {
|
|
|
777
556
|
commonService = inject(CommonService);
|
|
778
557
|
router = inject(Router);
|
|
779
558
|
translate = inject(TranslateService);
|
|
780
|
-
sessionManager = inject(SessionManagerService);
|
|
781
559
|
/* ----------------------------------------
|
|
782
560
|
TOKEN
|
|
783
561
|
---------------------------------------- */
|
|
@@ -823,13 +601,6 @@ class AuthService extends HTTPService {
|
|
|
823
601
|
}
|
|
824
602
|
this.notiService.success('Đăng nhập thành công');
|
|
825
603
|
TokenStorage.saveToken(res);
|
|
826
|
-
/* start session manager */
|
|
827
|
-
this.sessionManager.start({
|
|
828
|
-
refreshToken: () => this.refreshToken(),
|
|
829
|
-
logout: () => this.signOut(),
|
|
830
|
-
getToken: () => this.getToken(),
|
|
831
|
-
});
|
|
832
|
-
this.sessionManager.broadcastLogin();
|
|
833
604
|
if (returnUrl) {
|
|
834
605
|
this.router.navigateByUrl(returnUrl);
|
|
835
606
|
}
|
|
@@ -845,26 +616,11 @@ class AuthService extends HTTPService {
|
|
|
845
616
|
headers: new HttpHeaders().set('Content-Type', 'application/json'),
|
|
846
617
|
}));
|
|
847
618
|
}
|
|
848
|
-
/* ----------------------------------------
|
|
849
|
-
INIT SESSION (reload page)
|
|
850
|
-
---------------------------------------- */
|
|
851
|
-
initSession() {
|
|
852
|
-
const token = TokenStorage.getToken();
|
|
853
|
-
if (token) {
|
|
854
|
-
this.sessionManager.start({
|
|
855
|
-
refreshToken: () => this.refreshToken(),
|
|
856
|
-
logout: () => this.signOut(),
|
|
857
|
-
getToken: () => this.getToken(),
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
619
|
/* ----------------------------------------
|
|
862
620
|
LOGOUT
|
|
863
621
|
---------------------------------------- */
|
|
864
622
|
signOut() {
|
|
865
623
|
TokenStorage.clearToken();
|
|
866
|
-
this.sessionManager.broadcastLogout();
|
|
867
|
-
// this.sessionManager.stop();
|
|
868
624
|
const currentUrl = this.router.routerState.snapshot.url;
|
|
869
625
|
this.router.navigate(['/login'], {
|
|
870
626
|
queryParams: { returnUrl: currentUrl || '/' },
|
|
@@ -1168,6 +924,209 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.7", ngImpor
|
|
|
1168
924
|
}]
|
|
1169
925
|
}] });
|
|
1170
926
|
|
|
927
|
+
class SessionManagerService {
|
|
928
|
+
zone;
|
|
929
|
+
constructor(zone) {
|
|
930
|
+
this.zone = zone;
|
|
931
|
+
}
|
|
932
|
+
authService = inject(AuthService);
|
|
933
|
+
idleTimer;
|
|
934
|
+
refreshTimer;
|
|
935
|
+
heartbeatTimer;
|
|
936
|
+
static IDLE_MIN = 15;
|
|
937
|
+
REFRESH_BEFORE = 120;
|
|
938
|
+
get IDLE_TIME() {
|
|
939
|
+
return (SessionManagerService.IDLE_MIN || 0) * 60 * 1000;
|
|
940
|
+
}
|
|
941
|
+
LEADER_KEY = 'APP_SESSION_LEADER';
|
|
942
|
+
HEARTBEAT_KEY = 'APP_SESSION_HEARTBEAT';
|
|
943
|
+
ACTIVITY_KEY = 'APP_LAST_ACTIVITY';
|
|
944
|
+
SESSION_EVENT = 'APP_SESSION_EVENT';
|
|
945
|
+
LOGIN_EVENT = 'APP_LOGIN_EVENT';
|
|
946
|
+
LOGOUT_EVENT = 'APP_LOGOUT_EVENT';
|
|
947
|
+
ACTIVITY_EVENT = 'APP_ACTIVITY_EVENT';
|
|
948
|
+
TOKEN_REFRESH_EVENT = 'APP_TOKEN_REFRESH_EVENT';
|
|
949
|
+
tabId = crypto.randomUUID();
|
|
950
|
+
isLeader = false;
|
|
951
|
+
refreshLock = false;
|
|
952
|
+
channel = null;
|
|
953
|
+
/* -------------------------------- START -------------------------------- */
|
|
954
|
+
start() {
|
|
955
|
+
if (this.IDLE_TIME <= 0)
|
|
956
|
+
return;
|
|
957
|
+
console.log('SessionManagerService > start > IDLE_TIME:', SessionManagerService.IDLE_MIN);
|
|
958
|
+
if ('BroadcastChannel' in window) {
|
|
959
|
+
this.channel = new BroadcastChannel('APP_SESSION');
|
|
960
|
+
this.listenChannel();
|
|
961
|
+
}
|
|
962
|
+
this.listenActivity();
|
|
963
|
+
this.updateActivity();
|
|
964
|
+
this.resetIdle();
|
|
965
|
+
this.electLeader();
|
|
966
|
+
}
|
|
967
|
+
stop() {
|
|
968
|
+
clearTimeout(this.idleTimer);
|
|
969
|
+
clearTimeout(this.refreshTimer);
|
|
970
|
+
clearInterval(this.heartbeatTimer);
|
|
971
|
+
}
|
|
972
|
+
async login(username, password, orgid, returnUrl) {
|
|
973
|
+
var ret = await this.authService.signIn(username, password, orgid, returnUrl);
|
|
974
|
+
if (ret) {
|
|
975
|
+
console.log('SessionManagerService > broadcast LOGIN');
|
|
976
|
+
this.broadcast(this.LOGIN_EVENT);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
logout() {
|
|
980
|
+
this.authService.signOut();
|
|
981
|
+
this.broadcast(this.LOGOUT_EVENT);
|
|
982
|
+
}
|
|
983
|
+
/* -------------------------------- ACTIVITY -------------------------------- */
|
|
984
|
+
listenActivity() {
|
|
985
|
+
const events = ['mousemove', 'keydown', 'click', 'scroll'];
|
|
986
|
+
events.forEach((e) => {
|
|
987
|
+
window.addEventListener(e, this.onActivity, true);
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
onActivity = this.debounce(() => {
|
|
991
|
+
this.updateActivity();
|
|
992
|
+
this.resetIdle();
|
|
993
|
+
this.broadcast(this.ACTIVITY_EVENT);
|
|
994
|
+
}, 1000);
|
|
995
|
+
updateActivity() {
|
|
996
|
+
localStorage.setItem(this.ACTIVITY_KEY, Date.now().toString());
|
|
997
|
+
}
|
|
998
|
+
/* -------------------------------- IDLE -------------------------------- */
|
|
999
|
+
resetIdle() {
|
|
1000
|
+
clearTimeout(this.idleTimer);
|
|
1001
|
+
const last = Number(localStorage.getItem(this.ACTIVITY_KEY) || Date.now());
|
|
1002
|
+
const remain = this.IDLE_TIME - (Date.now() - last);
|
|
1003
|
+
if (remain <= 0) {
|
|
1004
|
+
this.authService.signOut();
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
this.zone.runOutsideAngular(() => {
|
|
1008
|
+
this.idleTimer = setTimeout(() => {
|
|
1009
|
+
this.zone.run(() => this.authService.signOut());
|
|
1010
|
+
}, remain);
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
/* -------------------------------- LEADER -------------------------------- */
|
|
1014
|
+
electLeader() {
|
|
1015
|
+
const leader = localStorage.getItem(this.LEADER_KEY);
|
|
1016
|
+
if (!leader) {
|
|
1017
|
+
this.becomeLeader();
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
this.checkLeaderHeartbeat();
|
|
1021
|
+
}
|
|
1022
|
+
becomeLeader() {
|
|
1023
|
+
this.isLeader = true;
|
|
1024
|
+
localStorage.setItem(this.LEADER_KEY, this.tabId);
|
|
1025
|
+
this.startHeartbeat();
|
|
1026
|
+
this.scheduleRefresh();
|
|
1027
|
+
}
|
|
1028
|
+
startHeartbeat() {
|
|
1029
|
+
this.heartbeatTimer = setInterval(() => {
|
|
1030
|
+
localStorage.setItem(this.HEARTBEAT_KEY, Date.now().toString());
|
|
1031
|
+
}, 2000);
|
|
1032
|
+
}
|
|
1033
|
+
checkLeaderHeartbeat() {
|
|
1034
|
+
setTimeout(() => {
|
|
1035
|
+
const beat = Number(localStorage.getItem(this.HEARTBEAT_KEY) || 0);
|
|
1036
|
+
if (Date.now() - beat > 5000) {
|
|
1037
|
+
this.becomeLeader();
|
|
1038
|
+
}
|
|
1039
|
+
}, 3000);
|
|
1040
|
+
}
|
|
1041
|
+
/* -------------------------------- REFRESH TOKEN -------------------------------- */
|
|
1042
|
+
scheduleRefresh() {
|
|
1043
|
+
if (!this.isLeader)
|
|
1044
|
+
return;
|
|
1045
|
+
clearTimeout(this.refreshTimer);
|
|
1046
|
+
const token = this.authService.getToken();
|
|
1047
|
+
if (!token)
|
|
1048
|
+
return;
|
|
1049
|
+
const exp = this.parseJwt(token).exp * 1000;
|
|
1050
|
+
const delay = exp - Date.now() - this.REFRESH_BEFORE * 1000;
|
|
1051
|
+
if (delay <= 0) {
|
|
1052
|
+
this.refreshToken();
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
this.refreshTimer = setTimeout(() => {
|
|
1056
|
+
this.refreshToken();
|
|
1057
|
+
}, delay);
|
|
1058
|
+
}
|
|
1059
|
+
async refreshToken() {
|
|
1060
|
+
if (!this.isLeader || this.refreshLock)
|
|
1061
|
+
return;
|
|
1062
|
+
this.refreshLock = true;
|
|
1063
|
+
try {
|
|
1064
|
+
const res = await this.authService.refreshToken();
|
|
1065
|
+
if (res?.IsSuccess) {
|
|
1066
|
+
this.broadcast(this.TOKEN_REFRESH_EVENT);
|
|
1067
|
+
this.scheduleRefresh();
|
|
1068
|
+
}
|
|
1069
|
+
else {
|
|
1070
|
+
this.logout();
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
catch {
|
|
1074
|
+
this.logout();
|
|
1075
|
+
}
|
|
1076
|
+
finally {
|
|
1077
|
+
this.refreshLock = false;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
/* -------------------------------- CHANNEL -------------------------------- */
|
|
1081
|
+
listenChannel() {
|
|
1082
|
+
if (!this.channel)
|
|
1083
|
+
return;
|
|
1084
|
+
this.channel.onmessage = (msg) => {
|
|
1085
|
+
const type = msg.data?.type;
|
|
1086
|
+
if (type === this.ACTIVITY_EVENT) {
|
|
1087
|
+
this.resetIdle();
|
|
1088
|
+
}
|
|
1089
|
+
if (type === this.LOGOUT_EVENT) {
|
|
1090
|
+
location.reload();
|
|
1091
|
+
}
|
|
1092
|
+
if (type === this.LOGIN_EVENT) {
|
|
1093
|
+
location.reload();
|
|
1094
|
+
}
|
|
1095
|
+
if (type === this.TOKEN_REFRESH_EVENT) {
|
|
1096
|
+
this.scheduleRefresh();
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
broadcast(type) {
|
|
1101
|
+
if (this.channel) {
|
|
1102
|
+
this.channel.postMessage({ type });
|
|
1103
|
+
}
|
|
1104
|
+
else {
|
|
1105
|
+
localStorage.setItem(this.SESSION_EVENT, JSON.stringify({ type, t: Date.now() }));
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
/* -------------------------------- UTILS -------------------------------- */
|
|
1109
|
+
debounce(fn, delay) {
|
|
1110
|
+
let timer;
|
|
1111
|
+
return () => {
|
|
1112
|
+
clearTimeout(timer);
|
|
1113
|
+
timer = setTimeout(() => fn(), delay);
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
parseJwt(token) {
|
|
1117
|
+
const payload = token.split('.')[1];
|
|
1118
|
+
return JSON.parse(atob(payload));
|
|
1119
|
+
}
|
|
1120
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: SessionManagerService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1121
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: SessionManagerService, providedIn: 'root' });
|
|
1122
|
+
}
|
|
1123
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: SessionManagerService, decorators: [{
|
|
1124
|
+
type: Injectable,
|
|
1125
|
+
args: [{
|
|
1126
|
+
providedIn: 'root',
|
|
1127
|
+
}]
|
|
1128
|
+
}], ctorParameters: () => [{ type: i0.NgZone }] });
|
|
1129
|
+
|
|
1171
1130
|
class CustomModalService {
|
|
1172
1131
|
modal;
|
|
1173
1132
|
constructor(modal) {
|
|
@@ -6377,6 +6336,7 @@ const fadeSlide = trigger('fadeSlide', [
|
|
|
6377
6336
|
class LayoutUser extends BaseComponent {
|
|
6378
6337
|
cms = inject(CommonService);
|
|
6379
6338
|
authService = inject(AuthService);
|
|
6339
|
+
sessionManager = inject(SessionManagerService);
|
|
6380
6340
|
breakpointObserver = inject(BreakpointObserver);
|
|
6381
6341
|
TokenStorage = TokenStorage;
|
|
6382
6342
|
isXSmall = false;
|
|
@@ -6408,7 +6368,7 @@ class LayoutUser extends BaseComponent {
|
|
|
6408
6368
|
this.goto('/admin/user_profile');
|
|
6409
6369
|
}
|
|
6410
6370
|
logout() {
|
|
6411
|
-
this.authService.signOut();
|
|
6371
|
+
this.sessionManager.authService.signOut();
|
|
6412
6372
|
}
|
|
6413
6373
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: LayoutUser, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
6414
6374
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.7", type: LayoutUser, isStandalone: true, selector: "layout-user", usesInheritance: true, ngImport: i0, template: "<nz-badge [nzSize]=\"'small'\" [nzCount]=\"0\">\n <button nz-button nzType=\"text\" nzSize=\"small\">\n <nz-icon nzType=\"bell\" nzTheme=\"outline\" style=\"color: #ffffff\" />\n </button>\n</nz-badge>\n\n<button\n *ngIf=\"!isXSmall && TokenStorage.getOrgName()\"\n [@fadeInOut]\n nz-button\n nzType=\"text\"\n nz-dropdown\n [nzDropdownMenu]=\"menuOrg\"\n style=\"height: 50px; color: #ffffff\"\n>\n <nz-icon nzType=\"cluster\" nzTheme=\"outline\" />\n {{ TokenStorage.getOrgName() }}\n</button>\n\n<nz-dropdown-menu #menuOrg=\"nzDropdownMenu\">\n <ul nz-menu>\n @for (org of lstOrg; track $index) {\n <li *ngIf=\"$index > 0\" nz-menu-divider></li>\n <li nz-menu-item (click)=\"changeOrg(org)\">\n <nz-icon nzType=\"swap\" nzTheme=\"outline\" /> {{ org.Name }}\n </li>\n }\n </ul>\n</nz-dropdown-menu>\n\n<button nz-button nzType=\"text\" nz-dropdown [nzDropdownMenu]=\"menuUser\" style=\"height: 50px; color: #ffffff\">\n <nz-icon nzType=\"user\" nzTheme=\"outline\" />\n {{ TokenStorage.getUserFullname() }}\n</button>\n\n<nz-dropdown-menu #menuUser=\"nzDropdownMenu\">\n <ul nz-menu>\n <li *ngIf=\"!(!isXSmall && TokenStorage.getOrgName())\" nz-menu-item>\n <nz-icon nzType=\"cluster\" nzTheme=\"outline\" /> {{ TokenStorage.getOrgName() }}\n </li>\n <li *ngIf=\"!(!isXSmall && TokenStorage.getOrgName())\" nz-menu-divider></li>\n <li nz-menu-item (click)=\"gotoSetting()\">\n <nz-icon nzType=\"setting\" nzTheme=\"outline\" /> {{ TranslateKey.SETTING | translate }}\n </li>\n <li nz-menu-divider></li>\n <li nz-menu-item (click)=\"logout()\">\n <nz-icon nzType=\"logout\" nzTheme=\"outline\" /> {{ TranslateKey.LOGOUT | translate }}\n </li>\n </ul>\n</nz-dropdown-menu>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i3.TranslatePipe, name: "translate" }, { kind: "ngmodule", type: NzLayoutModule }, { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i1$2.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: NzDropDownModule }, { kind: "directive", type: i4$2.NzMenuDirective, selector: "[nz-menu]", inputs: ["nzInlineIndent", "nzTheme", "nzMode", "nzInlineCollapsed", "nzSelectable"], outputs: ["nzClick"], exportAs: ["nzMenu"] }, { kind: "component", type: i4$2.NzMenuItemComponent, selector: "[nz-menu-item]", inputs: ["nzPaddingLeft", "nzDisabled", "nzSelected", "nzDanger", "nzMatchRouterExact", "nzMatchRouter"], exportAs: ["nzMenuItem"] }, { kind: "directive", type: i4$2.NzMenuDividerDirective, selector: "[nz-menu-divider]", exportAs: ["nzMenuDivider"] }, { kind: "directive", type: i5$3.NzDropDownDirective, selector: "[nz-dropdown]", inputs: ["nzDropdownMenu", "nzTrigger", "nzMatchWidthElement", "nzBackdrop", "nzClickHide", "nzDisabled", "nzVisible", "nzOverlayClassName", "nzOverlayStyle", "nzPlacement"], outputs: ["nzVisibleChange"], exportAs: ["nzDropdown"] }, { kind: "component", type: i5$3.NzDropdownMenuComponent, selector: "nz-dropdown-menu", exportAs: ["nzDropdownMenu"] }, { kind: "directive", type: i5$3.NzDropdownButtonDirective, selector: "[nz-button][nz-dropdown]" }, { kind: "ngmodule", type: NzGridModule }, { kind: "ngmodule", type: NzFlexModule }, { kind: "ngmodule", type: NzButtonModule }, { kind: "component", type: i8.NzButtonComponent, selector: "button[nz-button], a[nz-button]", inputs: ["nzBlock", "nzGhost", "nzSearch", "nzLoading", "nzDanger", "disabled", "tabIndex", "nzType", "nzShape", "nzSize"], exportAs: ["nzButton"] }, { kind: "directive", type: i9.ɵNzTransitionPatchDirective, selector: "[nz-button], nz-button-group, [nz-icon], nz-icon, [nz-menu-item], [nz-submenu], nz-select-top-control, nz-select-placeholder, nz-input-group", inputs: ["hidden"] }, { kind: "ngmodule", type: NzTreeModule }, { kind: "ngmodule", type: NzBackTopModule }, { kind: "ngmodule", type: NzDrawerModule }, { kind: "ngmodule", type: FormsModule }, { kind: "ngmodule", type: NzInputModule }, { kind: "ngmodule", type: NzSegmentedModule }, { kind: "ngmodule", type: NzBadgeModule }, { kind: "component", type: i8$1.NzBadgeComponent, selector: "nz-badge", inputs: ["nzShowZero", "nzShowDot", "nzStandalone", "nzDot", "nzOverflowCount", "nzColor", "nzStyle", "nzText", "nzTitle", "nzStatus", "nzCount", "nzOffset", "nzSize"], exportAs: ["nzBadge"] }], animations: [fadeInOut] });
|