fix: set default expires day of keystone_token

1. set default expires day of keystone_token
2. add tips when keystone_token is expired

Change-Id: Ib5bb97c3c790d9f5c239fc19bb76a95a231ca838
This commit is contained in:
zhangke 2022-03-03 10:08:52 +08:00
parent 757047a1cb
commit 29a0435392
4 changed files with 17 additions and 8 deletions

View File

@ -17,6 +17,7 @@ import { inject, observer } from 'mobx-react';
import { Typography } from 'antd'; import { Typography } from 'antd';
import { ModalAction } from 'containers/Action'; import { ModalAction } from 'containers/Action';
import { allCanReadPolicy } from 'resources/policy'; import { allCanReadPolicy } from 'resources/policy';
import { getLocalTime } from 'utils/time';
import styles from './index.less'; import styles from './index.less';
const { Paragraph } = Typography; const { Paragraph } = Typography;
@ -50,9 +51,10 @@ export default class Token extends ModalAction {
return this.token.value || ''; return this.token.value || '';
} }
get tokenExpiry() { get keystoneTokenExp() {
const { expires } = this.token; const { keystone_token_exp } = this.props.rootStore.user || {};
return expires || 0; const exp = getLocalTime(keystone_token_exp).valueOf();
return exp;
} }
getLeftStr = (value) => { getLeftStr = (value) => {
@ -79,9 +81,17 @@ export default class Token extends ModalAction {
}; };
get tips() { get tips() {
const now = Date.now();
if (now > this.keystoneTokenExp) {
return (
<span style={{ color: 'rgb(232, 104, 74)' }}>
{t('Keystone token is expired.')}
</span>
);
}
return t( return t(
'Please save your token properly and it will be valid for {left}.', 'Please save your token properly and it will be valid for {left}.',
{ left: this.getLeftStr(this.tokenExpiry) } { left: this.getLeftStr(this.keystoneTokenExp) }
); );
} }

View File

@ -1062,6 +1062,7 @@
"Keypair": "Keypair", "Keypair": "Keypair",
"Keypair Detail": "Keypair Detail", "Keypair Detail": "Keypair Detail",
"Keypair Info": "Keypair Info", "Keypair Info": "Keypair Info",
"Keystone token is expired.": "token has expired, please check whether the server time is correct and confirm whether the token is valid",
"Killed": "Killed", "Killed": "Killed",
"Kuwait": "Kuwait", "Kuwait": "Kuwait",
"Kyrgyzstan": "Kyrgyzstan", "Kyrgyzstan": "Kyrgyzstan",

View File

@ -1062,6 +1062,7 @@
"Keypair": "SSH密钥对", "Keypair": "SSH密钥对",
"Keypair Detail": "密钥详情", "Keypair Detail": "密钥详情",
"Keypair Info": "密钥信息", "Keypair Info": "密钥信息",
"Keystone token is expired.": "token已过期请检查服务器时间是否正确确认token是否有效",
"Killed": "终止", "Killed": "终止",
"Kuwait": "科威特", "Kuwait": "科威特",
"Kyrgyzstan": "吉尔吉斯", "Kyrgyzstan": "吉尔吉斯",

View File

@ -17,7 +17,6 @@ import { RouterStore } from 'mobx-react-router';
import { parse } from 'qs'; import { parse } from 'qs';
import client from 'client'; import client from 'client';
import { getQueryString } from 'utils/index'; import { getQueryString } from 'utils/index';
import { getLocalTime } from 'utils/time';
import { setLocalStorageItem } from 'utils/local-storage'; import { setLocalStorageItem } from 'utils/local-storage';
import { isEmpty, values } from 'lodash'; import { isEmpty, values } from 'lodash';
@ -135,7 +134,6 @@ export class RootStore {
this.policies = policies; this.policies = policies;
const { const {
keystone_token, keystone_token,
keystone_token_exp,
endpoints = {}, endpoints = {},
license = {}, license = {},
version = '', version = '',
@ -146,8 +144,7 @@ export class RootStore {
this.license = license || {}; this.license = license || {};
this.version = version; this.version = version;
this.updateUserRoles(user); this.updateUserRoles(user);
const exp = getLocalTime(keystone_token_exp).valueOf(); setLocalStorageItem('keystone_token', keystone_token);
setLocalStorageItem('keystone_token', keystone_token, 0, exp);
this.endpoints = endpoints; this.endpoints = endpoints;
} }