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 { ModalAction } from 'containers/Action';
import { allCanReadPolicy } from 'resources/policy';
import { getLocalTime } from 'utils/time';
import styles from './index.less';
const { Paragraph } = Typography;
@ -50,9 +51,10 @@ export default class Token extends ModalAction {
return this.token.value || '';
}
get tokenExpiry() {
const { expires } = this.token;
return expires || 0;
get keystoneTokenExp() {
const { keystone_token_exp } = this.props.rootStore.user || {};
const exp = getLocalTime(keystone_token_exp).valueOf();
return exp;
}
getLeftStr = (value) => {
@ -79,9 +81,17 @@ export default class Token extends ModalAction {
};
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(
'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 Detail": "Keypair Detail",
"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",
"Kuwait": "Kuwait",
"Kyrgyzstan": "Kyrgyzstan",

View File

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

View File

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