feat(auth): 支持企业微信重置密码

This commit is contained in:
sophie committed 2026-06-15 17:13:48 +08:00
1 parent 9bc4d1dd18
commit 6baeffba64
55 files changed
+2852 -546

No files matched your search

@@ -45,7 +45,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
employee_id: '',
phone_number: '',
});
const forgotPasswordForm = ref({ email: '' });
const forgotPasswordForm = ref({ employee_id: '', username: '' });
const isWecomLoggingIn = ref(false);
const wecomLoginDialog = ref<WecomLoginDialogContent | null>(null);
const wecomBindPrompt = ref<WecomBindPromptState | null>(null);
@@ -59,22 +59,43 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
saveAuthUser({ ...(user || {}) }, rememberMe.value);
};
const openForgotPasswordModal = () => {
forgotPasswordForm.value = {
employee_id: '',
username: loginUsername.value.trim(),
};
showForgotPasswordModal.value = true;
};
const handleForgotPassword = async () => {
if (!forgotPasswordForm.value.email) {
msg.warning(t('register.emailRequired'));
const employeeId = forgotPasswordForm.value.employee_id.trim();
const username = forgotPasswordForm.value.username.trim();
if (!employeeId) {
msg.warning(t('login.employeeIdRequired'));
return;
}
if (!username) {
msg.warning(t('login.usernameRequired'));
return;
}
try {
await requestJson('/api/user/reset-password-by-email', {
await requestJson('/api/user/reset-password-by-wecom', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(forgotPasswordForm.value),
body: JSON.stringify({ employee_id: employeeId, username }),
});
msg.success(t('login.passwordResetEmailSent'));
msg.success(t('login.passwordResetWecomSent'));
showForgotPasswordModal.value = false;
forgotPasswordForm.value = { email: '' };
forgotPasswordForm.value = { employee_id: '', username: '' };
} catch (e) {
console.error('Password reset error', e);
if (e instanceof BusinessError && e.code === 'AUTH.PASSWORD_RESET_RATE_LIMITED') {
const minutes =
Number(e.details?.retry_after_minutes)
|| Math.max(1, Math.ceil(Number(e.details?.retry_after_seconds || 300) / 60));
msg.error(t('login.passwordResetRateLimited', { minutes }));
return;
}
msg.error((e as Error)?.message || t('login.passwordResetRequestFailed'));
}
};
@@ -375,6 +396,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
rememberMe,
showRegisterModal,
showForgotPasswordModal,
openForgotPasswordModal,
registerForm,
forgotPasswordForm,
isWecomLoggingIn,