feat(auth):从JWT令牌中提取注册时间
- 在token工具函数中新增getRegisterTimeFromToken方法 - 修改客户端账户注册逻辑,将创建时间写入JWT令牌- 更新前后端代码以正确传递和解析registerTime字段 - 调整API调用逻辑,优先从令牌中获取注册时间 - 清理部分冗余代码和注释
This commit is contained in:
@@ -467,7 +467,6 @@ app.whenReady().then(() => {
|
||||
});
|
||||
|
||||
splashWindow.on('closed', () => splashWindow = null);
|
||||
|
||||
// 加载预注入的 HTML(图片已base64内联,无跨域问题)
|
||||
splashWindow.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(splashHtml)}`);
|
||||
splashWindow.once('ready-to-show', () => splashWindow?.show());
|
||||
@@ -477,7 +476,7 @@ app.whenReady().then(() => {
|
||||
setTimeout(() => {
|
||||
startSpringBoot();
|
||||
}, 200);
|
||||
|
||||
|
||||
// setTimeout(() => {
|
||||
// openAppIfNotOpened();
|
||||
// }, 200);
|
||||
|
||||
@@ -22,7 +22,6 @@ const electronAPI = {
|
||||
// 添加日志相关 API
|
||||
getLogDates: () => ipcRenderer.invoke('get-log-dates'),
|
||||
readLogFile: (logDate: string) => ipcRenderer.invoke('read-log-file', logDate),
|
||||
|
||||
// 关闭行为配置 API
|
||||
getCloseAction: () => ipcRenderer.invoke('get-close-action'),
|
||||
setCloseAction: (action: 'quit' | 'minimize' | 'tray') => ipcRenderer.invoke('set-close-action', action),
|
||||
|
||||
@@ -7,7 +7,7 @@ import {authApi} from './api/auth'
|
||||
import {deviceApi, type DeviceItem, type DeviceQuota} from './api/device'
|
||||
import {splashApi} from './api/splash'
|
||||
import {getOrCreateDeviceId} from './utils/deviceId'
|
||||
import {getToken, setToken, removeToken, getUsernameFromToken, getClientIdFromToken} from './utils/token'
|
||||
import {getToken, setToken, removeToken, getUsernameFromToken, getClientIdFromToken, getRegisterTimeFromToken} from './utils/token'
|
||||
import {CONFIG} from './api/http'
|
||||
import {getSettings} from './utils/settings'
|
||||
import LoginDialog from './components/auth/LoginDialog.vue'
|
||||
@@ -221,7 +221,7 @@ async function handleLoginSuccess(data: {
|
||||
vipExpireTime.value = data.expireTime ? new Date(data.expireTime) : null
|
||||
accountType.value = data.accountType || 'trial'
|
||||
deviceTrialExpired.value = data.deviceTrialExpired || false
|
||||
registerTime.value = data.registerTime || ''
|
||||
registerTime.value = getRegisterTimeFromToken(data.token)
|
||||
|
||||
const deviceId = await getOrCreateDeviceId()
|
||||
await deviceApi.register({
|
||||
@@ -322,7 +322,7 @@ async function checkAuth() {
|
||||
userPermissions.value = res.data.permissions || ''
|
||||
deviceTrialExpired.value = res.data.deviceTrialExpired || false
|
||||
accountType.value = res.data.accountType || 'trial'
|
||||
registerTime.value = res.data.registerTime || ''
|
||||
registerTime.value = getRegisterTimeFromToken(token)
|
||||
|
||||
if (res.data.expireTime) {
|
||||
vipExpireTime.value = new Date(res.data.expireTime)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export type HttpMethod = 'GET' | 'POST' | 'DELETE';
|
||||
const RUOYI_BASE = 'http://8.138.23.49:8085';
|
||||
// const RUOYI_BASE = 'http://192.168.1.89:8085';
|
||||
//const RUOYI_BASE = 'http://192.168.1.89:8085';
|
||||
export const CONFIG = {
|
||||
CLIENT_BASE: 'http://localhost:8081',
|
||||
RUOYI_BASE,
|
||||
|
||||
@@ -35,3 +35,15 @@ export function getClientIdFromToken(token?: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
export function getRegisterTimeFromToken(token?: string): string {
|
||||
try {
|
||||
const t = token || getToken();
|
||||
const payload = JSON.parse(atob(t.split('.')[1]));
|
||||
if (!payload.registerTime) return '';
|
||||
const date = new Date(payload.registerTime);
|
||||
return date.toISOString();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user