Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
472b530be3
397 files changed
+46450
-34171
No files matched your search
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* features/auth/api/auth.api.ts
|
||||
* 用途:封装登录、Casdoor/企微回调、注册和密码重置等认证域 HTTP 请求。
|
||||
* 依赖:shared/api/client。
|
||||
* 逻辑:auth views 与 composables 只调用本模块;后端暂保留 /api/user 路径以兼容既有接口。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
|
||||
export interface PasswordLoginInput {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
/** 使用当前认证模式的登录端点完成用户名密码认证。 */
|
||||
export const loginWithPassword = (api: string, input: PasswordLoginInput) =>
|
||||
requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
|
||||
/** 将 Casdoor 授权码兑换为 HXOPS 登录会话。 */
|
||||
export const loginWithCasdoorCode = (api: string, code: string, state: string | null) =>
|
||||
requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
|
||||
/** 读取 Casdoor 授权地址及后端签发的 state。 */
|
||||
export const getCasdoorAuthorizeUrl = (api: string, query: URLSearchParams) =>
|
||||
requestJson<{ url?: string; state?: string }>(`${api}?${query.toString()}`);
|
||||
|
||||
/** 将企微授权码兑换为 HXOPS 登录会话。 */
|
||||
export const loginWithWecomCode = (api: string, code: string, state: string | null) =>
|
||||
requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
|
||||
/** 读取企微授权地址及后端签发的 state。 */
|
||||
export const getWecomAuthorizeUrl = (api: string, redirectUri: string) =>
|
||||
requestJson<{ url?: string; state?: string }>(`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`);
|
||||
|
||||
/** 完成企微首次登录所需的本地用户匹配。 */
|
||||
export const completeWecomBind = (api: string, input: { binding_token: string; field: string; value: string }) =>
|
||||
requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
|
||||
/** 从登录页发起企业微信密码重置通知。 */
|
||||
export const requestPasswordResetByWecom = (employeeId: string, username: string) =>
|
||||
requestJson('/api/user/reset-password-by-wecom', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ employee_id: employeeId, username }),
|
||||
});
|
||||
|
||||
/** 使用重置链接中的 token 设置新密码。 */
|
||||
export const confirmPasswordReset = (token: string, newPassword: string) =>
|
||||
requestJson('/api/user/reset-password-confirm', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token, new_password: newPassword }),
|
||||
});
|
||||
|
||||
/** 注册 HXOPS 用户;后端负责后续 Casdoor 用户同步。 */
|
||||
export const registerUser = (form: Record<string, unknown>) =>
|
||||
requestJson('/api/user/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form),
|
||||
});
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/auth/composables/useLogin.ts
|
||||
* 登录页编排层:组合认证、公告展示与 OAuth 回调,provide 给 LoginView 子组件。
|
||||
* 依赖:auth.store、linked-nav.store、useLoginAuth、useLoginLanding。
|
||||
* 逻辑:登录成功后预取关联服务侧栏入口,减少进入 Chat/工作台后的入口闪现。
|
||||
*/
|
||||
import { onMounted, reactive } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
@@ -12,6 +14,8 @@ import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import loginBg from '@/assets/login-bg.png';
|
||||
import { DEFAULT_POST_LOGIN_AGENT_ID } from '@/features/workspace/types/workspace.types';
|
||||
import { useWorkspaceLocale } from '@/features/workspace/composables/useWorkspaceLocale';
|
||||
import { continuationLocation, readSsoContinuation } from '@/features/sso';
|
||||
import { useLinkedNavStore } from '@/features/sso/stores/linked-nav.store';
|
||||
import { useLoginAuth } from './useLoginAuth';
|
||||
import { useLoginLanding } from './useLoginLanding';
|
||||
|
||||
@@ -21,6 +25,7 @@ export function useLogin() {
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const linkedNav = useLinkedNavStore();
|
||||
const { setThemePreference, appliedTheme } = useTheme();
|
||||
|
||||
const deps = { t, locale, msg, router, route, setThemePreference, appliedTheme };
|
||||
@@ -28,11 +33,23 @@ export function useLogin() {
|
||||
|
||||
const completePasswordLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
void linkedNav.ensureLoaded({ force: true });
|
||||
const continuation = readSsoContinuation();
|
||||
if (continuation) {
|
||||
await router.replace(continuationLocation(continuation));
|
||||
return;
|
||||
}
|
||||
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||
};
|
||||
|
||||
const completeOAuthLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
void linkedNav.ensureLoaded({ force: true });
|
||||
const continuation = readSsoContinuation();
|
||||
if (continuation) {
|
||||
await router.replace(continuationLocation(continuation));
|
||||
return;
|
||||
}
|
||||
await router.replace('/workspace/applications');
|
||||
};
|
||||
|
||||
@@ -58,7 +75,8 @@ export function useLogin() {
|
||||
|
||||
authStore.syncFromStorage();
|
||||
if (authStore.isLoggedIn) {
|
||||
await router.replace('/workspace/applications');
|
||||
const continuation = readSsoContinuation();
|
||||
await router.replace(continuation ? continuationLocation(continuation) : '/workspace/applications');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* features/auth/composables/useLoginAuth.ts
|
||||
*
|
||||
* 用途:封装登录表单、记住我偏好、企微/Casdoor OAuth 回调、注册与找回密码逻辑。
|
||||
* 依赖:shared/utils/auth、requestJson、WeCom/Casdoor 工具函数。
|
||||
* 依赖:shared/utils/auth、auth.api、WeCom/Casdoor 工具函数。
|
||||
* 逻辑:密码登录成功后根据“记住我”同步本地登录态与 remembered username/password;
|
||||
* OAuth 登录仅负责认证,不自动写入 remember 偏好,避免用户未明确选择时持久化登录页账号。
|
||||
*/
|
||||
@@ -22,7 +22,17 @@ import {
|
||||
saveRememberedLoginPreference,
|
||||
saveRememberedLoginProfile,
|
||||
} from '@/shared/utils/auth';
|
||||
import { BusinessError, requestJson } from '@/shared/api/client';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import {
|
||||
completeWecomBind,
|
||||
getCasdoorAuthorizeUrl,
|
||||
getWecomAuthorizeUrl,
|
||||
loginWithCasdoorCode,
|
||||
loginWithPassword,
|
||||
loginWithWecomCode,
|
||||
registerUser,
|
||||
requestPasswordResetByWecom,
|
||||
} from '../api/auth.api';
|
||||
import { DEFAULT_POST_LOGIN_AGENT_ID } from '@/features/workspace/types/workspace.types';
|
||||
import type { WecomBindPromptState, WecomLoginDialogContent } from '@/features/workspace/types/workspace.types';
|
||||
import type { LoginDeps } from './login.deps';
|
||||
@@ -127,11 +137,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await requestJson('/api/user/reset-password-by-wecom', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ employee_id: employeeId, username }),
|
||||
});
|
||||
await requestPasswordResetByWecom(employeeId, username);
|
||||
msg.success(t('login.passwordResetWecomSent'));
|
||||
showForgotPasswordModal.value = false;
|
||||
forgotPasswordForm.value = { employee_id: '', username: '' };
|
||||
@@ -173,13 +179,9 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
const loginApi = isCasdoorMode
|
||||
? (config.auth?.casdoor?.passwordLoginApi || '/api/user/casdoor/password-login')
|
||||
: '/api/user/login';
|
||||
const user = await requestJson<Record<string, unknown>>(loginApi, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: loginUsername.value.trim(),
|
||||
password: loginPassword.value,
|
||||
}),
|
||||
const user = await loginWithPassword(loginApi, {
|
||||
username: loginUsername.value.trim(),
|
||||
password: loginPassword.value,
|
||||
});
|
||||
|
||||
persistLoginUser(user);
|
||||
@@ -221,11 +223,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
}
|
||||
try {
|
||||
const api = config.auth.casdoor.loginApi || '/api/user/casdoor/login';
|
||||
const data = await requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
const data = await loginWithCasdoorCode(api, code, state);
|
||||
persistLoginUser(data);
|
||||
sessionStorage.removeItem('hxops_casdoor_state');
|
||||
await completeOAuthLogin();
|
||||
@@ -267,7 +265,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
const qs = new URLSearchParams({ redirect_uri: redirectUri, default_provider: 'wecom' });
|
||||
const hint = (config.auth.casdoor as { wecomProviderHint?: string }).wecomProviderHint?.trim();
|
||||
if (hint) qs.set('provider_hint', hint);
|
||||
const data = await requestJson<{ url?: string; state?: string }>(`${api}?${qs.toString()}`);
|
||||
const data = await getCasdoorAuthorizeUrl(api, qs);
|
||||
if (!data?.url) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
@@ -280,9 +278,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
const callbackPath = wecomCfg.callbackPath || '/login';
|
||||
const redirectUri = `${window.location.origin}${callbackPath}`;
|
||||
const api = wecomCfg.authorizeApi || '/api/user/wecom/authorize-url';
|
||||
const data = await requestJson<{ url?: string; state?: string }>(
|
||||
`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`,
|
||||
);
|
||||
const data = await getWecomAuthorizeUrl(api, redirectUri);
|
||||
if (!data?.url) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
@@ -336,14 +332,10 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
wecomBindPrompt.value.error = '';
|
||||
try {
|
||||
const api = config.auth.wecom.completeBindApi || '/api/user/wecom/complete-bind';
|
||||
const data = await requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
binding_token: wecomBindPrompt.value.binding_token,
|
||||
field: wecomBindPrompt.value.field,
|
||||
value: wecomBindPrompt.value.value.trim(),
|
||||
}),
|
||||
const data = await completeWecomBind(api, {
|
||||
binding_token: wecomBindPrompt.value.binding_token,
|
||||
field: wecomBindPrompt.value.field,
|
||||
value: wecomBindPrompt.value.value.trim(),
|
||||
});
|
||||
wecomLoginDialog.value = null;
|
||||
persistLoginUser(data);
|
||||
@@ -389,11 +381,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
isWecomLoggingIn.value = true;
|
||||
try {
|
||||
const api = config.auth.wecom.loginApi || '/api/user/wecom/login';
|
||||
const data = await requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
const data = await loginWithWecomCode(api, code, state);
|
||||
wecomLoginDialog.value = null;
|
||||
persistLoginUser(data);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
@@ -434,11 +422,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await requestJson('/api/user/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form),
|
||||
});
|
||||
await registerUser(form);
|
||||
msg.success(t('register.success'));
|
||||
showRegisterModal.value = false;
|
||||
registerForm.value = {
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
/**
|
||||
* features/auth/index.ts
|
||||
* 认证 feature 对外导出:store、登录 composable、用户 API。
|
||||
* 认证 feature 对外导出:store、登录 composable 与认证 API。
|
||||
*/
|
||||
export { useAuthStore, bindAuthStoreSync } from './stores/auth.store';
|
||||
export { useLogin } from './composables/useLogin';
|
||||
export {
|
||||
getUserProfile,
|
||||
getLeaveBalance,
|
||||
submitLeaveWorkflow,
|
||||
resetPasswordByWecom,
|
||||
resetPasswordConfirm,
|
||||
getUserAgent,
|
||||
listUserAgents,
|
||||
listAgentGuides,
|
||||
type LeaveBalanceResult,
|
||||
type LeaveWorkflowSubmitResult,
|
||||
} from './api/user.api';
|
||||
export * from './api/auth.api';
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* features/auth/views/ResetPasswordView.vue
|
||||
* 企微 textcard / 邮件链接重置密码页(/reset-password?token=...)。
|
||||
* 依赖:user.api resetPasswordConfirm、vue-i18n、MinimalShell。
|
||||
* 依赖:auth.api confirmPasswordReset、vue-i18n、MinimalShell。
|
||||
* 逻辑:校验 token 与两次密码一致后调 confirm 接口,成功后跳转 /login。
|
||||
*/
|
||||
import { onMounted, ref } from 'vue';
|
||||
@@ -10,7 +10,7 @@ import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Lock, AlertCircle, CheckCircle } from 'lucide-vue-next';
|
||||
import MinimalShell from '@/shared/layouts/MinimalShell.vue';
|
||||
import { resetPasswordConfirm } from '@/features/auth/api/user.api';
|
||||
import { confirmPasswordReset } from '@/features/auth/api/auth.api';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { resolveCasdoorErrorMessage } from '@/shared/utils/casdoor';
|
||||
|
||||
@@ -65,7 +65,7 @@ onMounted(() => {
|
||||
|
||||
/**
|
||||
* 提交新密码并重置 token。
|
||||
* 核心逻辑:前端校验 → resetPasswordConfirm → 成功 3 秒后跳转登录页。
|
||||
* 核心逻辑:前端校验 → confirmPasswordReset → 成功 3 秒后跳转登录页。
|
||||
*/
|
||||
const handleReset = async () => {
|
||||
if (!token.value) {
|
||||
@@ -91,7 +91,7 @@ const handleReset = async () => {
|
||||
message.value = '';
|
||||
|
||||
try {
|
||||
await resetPasswordConfirm(token.value, password.value);
|
||||
await confirmPasswordReset(token.value, password.value);
|
||||
status.value = 'success';
|
||||
message.value = t('resetPassword.successRedirect');
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in new issue
Block a user