Skip to content

Commit

Permalink
Merge pull request #600 from jumpserver/dev
Browse files Browse the repository at this point in the history
v2.22.0-rc4
  • Loading branch information
BaiJiangJie authored May 18, 2022
2 parents 742b2f7 + 2a9aa41 commit 900f4b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app/services/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import {LocalStorageService, LogService} from './share';
import {SettingService} from '@app/services/setting';
import {AuthInfo, ConnectData, SystemUser, TreeNode, Endpoint, Protocol, View} from '@app/model';
import * as CryptoJS from 'crypto-js';
import {getCookie, setCookie} from '@app/utils/common';

declare function unescape(s: string): string;

function gotoLogin() {
const currentPath = encodeURI(document.location.pathname + document.location.search);
window.location.href = document.location.origin + '/core/auth/login/?next=' + currentPath;
}

@Injectable()
export class AppService {
// user:User = user ;
Expand Down Expand Up @@ -56,6 +62,18 @@ export class AppService {
}
return;
}

// Determine whether the user has logged in
const sessionExpire = getCookie('jms_session_expire');
if (!sessionExpire) {
gotoLogin();
return;
} else if (sessionExpire === 'close') {
setInterval(() => {
setCookie('jms_session_expire', sessionExpire, 120);
}, 10 * 1000);
}

this._http.getUserProfile().subscribe(
user => {
Object.assign(User, user);
Expand All @@ -65,10 +83,9 @@ export class AppService {
err => {
// this._logger.error(err);
User.logined = false;
const currentPath = encodeURI(document.location.pathname + document.location.search);
const token = this.getQueryString('token');
if (!token) {
window.location.href = document.location.origin + '/core/auth/login/?next=' + currentPath;
gotoLogin();
}
// this._router.navigate(['login']);
},
Expand Down
7 changes: 7 additions & 0 deletions src/app/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export function newTerminal(fontSize?: number) {
});
}

export function setCookie(name, value, seconds) {
const d = new Date();
d.setTime(d.getTime() + seconds * 1000);
const expires = 'expires=' + d.toUTCString();
document.cookie = name + '=' + value + '; ' + expires;
}

export function getCookie(name: string): string {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
Expand Down

0 comments on commit 900f4b7

Please sign in to comment.