feat: 支持账号导入与强制改密

- 新增账号导入模板下载、导入校验和默认密码重置标记

- 支持管理员重置密码并在登录后强制跳转修改密码

- 管理端与用户中心接入强密码校验和密码重置流程
This commit is contained in:
2026-03-18 21:56:05 +08:00
parent 14c78d54f5
commit 5d3c7d8692
40 changed files with 1720 additions and 142 deletions

View File

@@ -18,6 +18,10 @@ import {
logoutApi,
} from '#/api';
import { $t } from '#/locales';
import {
buildForcePasswordRoute,
shouldForcePasswordChange,
} from '#/utils/password-reset';
export const useAuthStore = defineStore('auth', () => {
const accessStore = useAccessStore();
@@ -28,6 +32,7 @@ export const useAuthStore = defineStore('auth', () => {
async function finalizeLogin(
accessToken: string,
forceChangePassword?: boolean,
options: {
notify?: boolean;
onSuccess?: () => Promise<void> | void;
@@ -47,8 +52,17 @@ export const useAuthStore = defineStore('auth', () => {
userStore.setUserInfo(userInfo);
accessStore.setAccessCodes(accessCodes);
const forcePasswordChange = shouldForcePasswordChange(
userInfo,
forceChangePassword,
);
if (accessStore.loginExpired) {
accessStore.setLoginExpired(false);
}
if (forcePasswordChange) {
await router.push(buildForcePasswordRoute());
} else if (!options.skipRedirect) {
const homePath =
userInfo.homePath || preferences.app.defaultHomePath || '/';
@@ -81,10 +95,12 @@ export const useAuthStore = defineStore('auth', () => {
) {
try {
loginLoading.value = true;
const { token: accessToken } = await loginApi(params);
const { forceChangePassword, token: accessToken } = await loginApi(params);
if (accessToken) {
return await finalizeLogin(accessToken, { onSuccess });
return await finalizeLogin(accessToken, forceChangePassword, {
onSuccess,
});
}
} finally {
loginLoading.value = false;
@@ -96,13 +112,15 @@ export const useAuthStore = defineStore('auth', () => {
}
async function authDevLogin(account: string) {
const { token: accessToken } = await devLoginApi({ account });
const { forceChangePassword, token: accessToken } = await devLoginApi({
account,
});
if (!accessToken) {
return {
userInfo: null,
};
}
return finalizeLogin(accessToken, {
return finalizeLogin(accessToken, forceChangePassword, {
notify: false,
skipRedirect: true,
});