fix(password): 优化修改密码相关bug
This commit is contained in:
1 parent
3837a8669e
commit
1de4b78181
5 files changed
+344
-38
No files matched your search
@@ -36,6 +36,31 @@ const messages = {
|
||||
passwordResetEmailSent: '如果账号存在,重置链接已发送到您的邮箱。',
|
||||
passwordResetRequestFailed: '请求密码重置失败',
|
||||
casdoorLogin: 'Login with Casdoor',
|
||||
casdoorErrors: {
|
||||
invalidCredentials: 'Incorrect username or password',
|
||||
codeExpired: 'Login session expired, please sign in again',
|
||||
stateExpired: 'Login session expired, please try again',
|
||||
accessDenied: 'Login was cancelled or denied',
|
||||
configError: 'Authentication service is unavailable. Please contact the administrator.',
|
||||
authFailed: 'Authentication failed, please try again',
|
||||
passwordPolicy: 'New password does not meet security requirements',
|
||||
setPasswordFailed: 'Failed to change password. Please try again or contact the administrator.',
|
||||
incorrectCurrentPassword: 'Current password is incorrect',
|
||||
userNotInIdp: 'Your account has not been registered in the authentication system. Please contact the administrator to sync your account before changing your password.',
|
||||
},
|
||||
casdoorDialogTitles: {
|
||||
userNotFound: 'No local account matched',
|
||||
userNotInIdp: 'Account not registered in authentication system',
|
||||
accountDisabled: 'Account is disabled',
|
||||
sessionExpired: 'Login session expired',
|
||||
configError: 'Authentication service error',
|
||||
accessDenied: 'Login was not completed',
|
||||
loginFailed: 'Login failed',
|
||||
},
|
||||
casdoorDialogDetails: {
|
||||
contactAdmin: 'If the problem persists, please contact the administrator.',
|
||||
retryLogin: 'Please close this dialog and sign in again.',
|
||||
},
|
||||
wecomLogin: 'Login with WeCom',
|
||||
wecomConnecting: 'Connecting to WeCom...',
|
||||
wecomStartFailed: 'Failed to start WeCom login',
|
||||
@@ -1502,6 +1527,7 @@ const messages = {
|
||||
newPassword: 'New Password',
|
||||
confirmPassword: 'Confirm Password',
|
||||
changePassword: 'Change Password',
|
||||
changingPassword: 'Changing...',
|
||||
changePasswordContactAdmin: 'Please contact the administrator to change your password.'
|
||||
},
|
||||
feedback: {
|
||||
@@ -1598,6 +1624,31 @@ const messages = {
|
||||
passwordResetEmailSent: '如果账号存在,重置链接已发送到您的邮箱。',
|
||||
passwordResetRequestFailed: '请求密码重置失败',
|
||||
casdoorLogin: 'Casdoor 登录',
|
||||
casdoorErrors: {
|
||||
invalidCredentials: '用户名或密码错误',
|
||||
codeExpired: '登录会话已过期,请重新登录',
|
||||
stateExpired: '登录会话已过期,请重试',
|
||||
accessDenied: '登录已取消或被拒绝',
|
||||
configError: '认证服务暂不可用,请联系管理员',
|
||||
authFailed: '登录失败,请稍后重试',
|
||||
passwordPolicy: '新密码不符合安全要求',
|
||||
setPasswordFailed: '修改密码失败,请稍后重试或联系管理员',
|
||||
incorrectCurrentPassword: '当前密码不正确',
|
||||
userNotInIdp: '您的账号尚未在统一认证系统中开通,请联系管理员同步账号后再修改密码。',
|
||||
},
|
||||
casdoorDialogTitles: {
|
||||
userNotFound: '未匹配到本地账号',
|
||||
userNotInIdp: '认证系统中无此账号',
|
||||
accountDisabled: '账号已禁用',
|
||||
sessionExpired: '登录会话已过期',
|
||||
configError: '认证服务异常',
|
||||
accessDenied: '登录未完成',
|
||||
loginFailed: '登录失败',
|
||||
},
|
||||
casdoorDialogDetails: {
|
||||
contactAdmin: '若问题持续出现,请联系管理员处理。',
|
||||
retryLogin: '请关闭此窗口后重新登录。',
|
||||
},
|
||||
wecomLogin: '企业微信登录',
|
||||
wecomConnecting: '正在连接企业微信...',
|
||||
wecomStartFailed: '启动企业微信登录失败',
|
||||
@@ -3044,6 +3095,7 @@ const messages = {
|
||||
newPassword: '新密码',
|
||||
confirmPassword: '确认密码',
|
||||
changePassword: '修改密码',
|
||||
changingPassword: '修改中...',
|
||||
changePasswordContactAdmin: '请联系管理员修改'
|
||||
},
|
||||
feedback: {
|
||||
@@ -3129,6 +3181,31 @@ const messages = {
|
||||
forgotPasswordDesc: '輸入您的郵箱以重設密碼',
|
||||
findPassword: '找回密碼',
|
||||
casdoorLogin: 'Casdoor 登入',
|
||||
casdoorErrors: {
|
||||
invalidCredentials: '用戶名或密碼錯誤',
|
||||
codeExpired: '登入會話已過期,請重新登入',
|
||||
stateExpired: '登入會話已過期,請重試',
|
||||
accessDenied: '登入已取消或被拒絕',
|
||||
configError: '認證服務暫不可用,請聯繫管理員',
|
||||
authFailed: '登入失敗,請稍後重試',
|
||||
passwordPolicy: '新密碼不符合安全要求',
|
||||
setPasswordFailed: '修改密碼失敗,請稍後重試或聯繫管理員',
|
||||
incorrectCurrentPassword: '當前密碼不正確',
|
||||
userNotInIdp: '您的賬號尚未在統一認證系統中開通,請聯繫管理員同步賬號後再修改密碼。',
|
||||
},
|
||||
casdoorDialogTitles: {
|
||||
userNotFound: '未匹配到本地賬號',
|
||||
userNotInIdp: '認證系統中無此賬號',
|
||||
accountDisabled: '賬號已禁用',
|
||||
sessionExpired: '登入會話已過期',
|
||||
configError: '認證服務異常',
|
||||
accessDenied: '登入未完成',
|
||||
loginFailed: '登入失敗',
|
||||
},
|
||||
casdoorDialogDetails: {
|
||||
contactAdmin: '若問題持續出現,請聯繫管理員處理。',
|
||||
retryLogin: '請關閉此窗口後重新登入。',
|
||||
},
|
||||
wecomLogin: '企業微信登錄',
|
||||
wecomConnecting: '正在連接企業微信...',
|
||||
wecomStartFailed: '啟動企業微信登錄失敗',
|
||||
@@ -4380,6 +4457,7 @@ const messages = {
|
||||
newPassword: '新密碼',
|
||||
confirmPassword: '確認密碼',
|
||||
changePassword: '修改密碼',
|
||||
changingPassword: '修改中...',
|
||||
changePasswordContactAdmin: '請聯繫管理員修改'
|
||||
},
|
||||
feedback: {
|
||||
@@ -4465,6 +4543,31 @@ const messages = {
|
||||
forgotPasswordDesc: 'กรอกอีเมลเพื่อรีเซ็ตรหัสผ่าน',
|
||||
findPassword: 'ค้นหารหัสผ่าน',
|
||||
casdoorLogin: 'เข้าสู่ระบบด้วย Casdoor',
|
||||
casdoorErrors: {
|
||||
invalidCredentials: 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง',
|
||||
codeExpired: 'เซสชันการเข้าสู่ระบบหมดอายุแล้ว กรุณาเข้าสู่ระบบใหม่',
|
||||
stateExpired: 'เซสชันการเข้าสู่ระบบหมดอายุแล้ว กรุณาลองใหม่',
|
||||
accessDenied: 'การเข้าสู่ระบบถูกยกเลิกหรือถูกปฏิเสธ',
|
||||
configError: 'บริการยืนยันตัวตนไม่พร้อมใช้งาน กรุณาติดต่อผู้ดูแลระบบ',
|
||||
authFailed: 'เข้าสู่ระบบไม่สำเร็จ กรุณาลองใหม่',
|
||||
passwordPolicy: 'รหัสผ่านใหม่ไม่ตรงตามข้อกำหนดด้านความปลอดภัย',
|
||||
setPasswordFailed: 'เปลี่ยนรหัสผ่านไม่สำเร็จ กรุณาลองใหม่หรือติดต่อผู้ดูแลระบบ',
|
||||
incorrectCurrentPassword: 'รหัสผ่านปัจจุบันไม่ถูกต้อง',
|
||||
userNotInIdp: 'บัญชีของคุณยังไม่ได้ลงทะเบียนในระบบยืนยันตัวตน กรุณาติดต่อผู้ดูแลระบบเพื่อซิงค์บัญชีก่อนเปลี่ยนรหัสผ่าน',
|
||||
},
|
||||
casdoorDialogTitles: {
|
||||
userNotFound: 'ไม่พบบัญชีในระบบที่ตรงกัน',
|
||||
userNotInIdp: 'ไม่พบบัญชีในระบบยืนยันตัวตน',
|
||||
accountDisabled: 'บัญชีถูกปิดใช้งาน',
|
||||
sessionExpired: 'เซสชันการเข้าสู่ระบบหมดอายุ',
|
||||
configError: 'บริการยืนยันตัวตนผิดปกติ',
|
||||
accessDenied: 'การเข้าสู่ระบบยังไม่สำเร็จ',
|
||||
loginFailed: 'เข้าสู่ระบบไม่สำเร็จ',
|
||||
},
|
||||
casdoorDialogDetails: {
|
||||
contactAdmin: 'หากปัญหายังคงอยู่ กรุณาติดต่อผู้ดูแลระบบ',
|
||||
retryLogin: 'กรุณาปิดหน้าต่างนี้แล้วเข้าสู่ระบบใหม่',
|
||||
},
|
||||
wecomLogin: 'เข้าสู่ระบบด้วย WeCom',
|
||||
wecomConnecting: 'กำลังเชื่อมต่อ WeCom...',
|
||||
wecomStartFailed: 'เริ่มต้นการเข้าสู่ระบบด้วย WeCom ไม่สำเร็จ',
|
||||
@@ -5659,6 +5762,7 @@ const messages = {
|
||||
newPassword: 'รหัสผ่านใหม่',
|
||||
confirmPassword: 'ยืนยันรหัสผ่าน',
|
||||
changePassword: 'เปลี่ยนรหัสผ่าน',
|
||||
changingPassword: 'กำลังเปลี่ยน...',
|
||||
changePasswordContactAdmin: 'กรุณาติดต่อผู้ดูแลระบบเพื่อเปลี่ยนรหัสผ่าน'
|
||||
},
|
||||
feedback: {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { BusinessError } from '../api/client';
|
||||
|
||||
type TranslateFn = (key: string, params?: Record<string, unknown>) => string;
|
||||
|
||||
function cleanText(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : String(value ?? '').trim();
|
||||
}
|
||||
|
||||
export function pickCasdoorErrorCode(err: BusinessError): string {
|
||||
const code = cleanText(err.code);
|
||||
if (code.startsWith('CASDOOR_') || code === 'ACCOUNT_DISABLED' || code === 'AUTH.INCORRECT_CURRENT_PASSWORD') {
|
||||
return code;
|
||||
}
|
||||
const detailsCode = cleanText(err.details?.error_code);
|
||||
if (detailsCode) return detailsCode;
|
||||
const raw = cleanText(err.message).toLowerCase();
|
||||
if (raw.includes('invalid or expired casdoor state')) return 'CASDOOR_STATE_EXPIRED';
|
||||
if (raw.includes('invalid_grant')) return 'CASDOOR_INVALID_CREDENTIALS';
|
||||
if (raw.includes("doesn't exist") || raw.includes('does not exist')) return 'CASDOOR_USER_NOT_IN_IDP';
|
||||
return code;
|
||||
}
|
||||
|
||||
export function resolveCasdoorErrorMessage(err: BusinessError, t: TranslateFn): string {
|
||||
const errorCode = pickCasdoorErrorCode(err);
|
||||
const keyMap: Record<string, string> = {
|
||||
CASDOOR_INVALID_CREDENTIALS: 'login.casdoorErrors.invalidCredentials',
|
||||
CASDOOR_CODE_EXPIRED: 'login.casdoorErrors.codeExpired',
|
||||
CASDOOR_STATE_EXPIRED: 'login.casdoorErrors.stateExpired',
|
||||
CASDOOR_USER_NOT_FOUND: 'workspace.msg.casdoorNotMatchedContactAdmin',
|
||||
ACCOUNT_DISABLED: 'login.accountDisabled',
|
||||
CASDOOR_ACCESS_DENIED: 'login.casdoorErrors.accessDenied',
|
||||
CASDOOR_CONFIG_ERROR: 'login.casdoorErrors.configError',
|
||||
CASDOOR_AUTH_FAILED: 'login.casdoorErrors.authFailed',
|
||||
CASDOOR_PASSWORD_POLICY: 'login.casdoorErrors.passwordPolicy',
|
||||
CASDOOR_SET_PASSWORD_FAILED: 'login.casdoorErrors.setPasswordFailed',
|
||||
CASDOOR_USER_NOT_IN_IDP: 'login.casdoorErrors.userNotInIdp',
|
||||
'AUTH.INCORRECT_CURRENT_PASSWORD': 'login.casdoorErrors.incorrectCurrentPassword',
|
||||
'VALIDATION.INVALID_PARAM': 'login.casdoorErrors.stateExpired',
|
||||
};
|
||||
const key = keyMap[errorCode];
|
||||
if (key) return t(key);
|
||||
const raw = cleanText(err.message);
|
||||
if (raw === 'Incorrect username or password') return t('login.casdoorErrors.invalidCredentials');
|
||||
if (raw === 'Incorrect current password') return t('login.casdoorErrors.incorrectCurrentPassword');
|
||||
if (raw === 'Invalid or expired Casdoor state') return t('login.casdoorErrors.stateExpired');
|
||||
return raw || t('login.casdoorErrors.authFailed');
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { useMessage } from '../composables/useMessage';
|
||||
import { useIsMobile } from '../composables/useIsMobile';
|
||||
import loginBg from '../assets/login-bg.png';
|
||||
|
||||
import { resolveCasdoorErrorMessage } from '../utils/casdoor';
|
||||
import {
|
||||
buildWecomLoginDialogContent,
|
||||
formatWecomFieldLabel,
|
||||
@@ -461,18 +462,7 @@ const handleLogin = async (event?: Event) => {
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
const rawError = String(err.message || '');
|
||||
const errorCode = String(err.code || '');
|
||||
let errorText = rawError || t('login.failed');
|
||||
const loginMode = String(config.auth?.loginMode || 'casdoor').toLowerCase();
|
||||
if (loginMode === 'casdoor') {
|
||||
if (errorCode === 'CASDOOR_USER_NOT_FOUND') {
|
||||
errorText = t('workspace.msg.casdoorNotMatchedContactAdmin');
|
||||
} else if (errorCode === 'ACCOUNT_DISABLED') {
|
||||
errorText = t('login.accountDisabled');
|
||||
} else if (rawError.includes('invalid_grant')) {
|
||||
errorText = t('login.incorrectPassword');
|
||||
}
|
||||
}
|
||||
let errorText = resolveCasdoorErrorMessage(err, t);
|
||||
if (rawError === 'User not found') errorText = t('login.userNotFound');
|
||||
if (rawError === 'Incorrect password') errorText = t('login.incorrectPassword');
|
||||
if (rawError === 'Account is disabled') errorText = t('login.accountDisabled');
|
||||
@@ -501,8 +491,7 @@ const tryCasdoorCallbackLogin = async () => {
|
||||
// strict frontend equality check to avoid false negatives during rollout.
|
||||
const shouldStrictCheck = !!expectedState && !!state && !String(state).startsWith('hxops_casdoor_v1.');
|
||||
if (shouldStrictCheck && state !== expectedState) {
|
||||
// Prevent CSRF/state mismatch replay.
|
||||
msg.error('Invalid or expired Casdoor state');
|
||||
msg.error(t('login.casdoorErrors.stateExpired'));
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
@@ -521,14 +510,8 @@ const tryCasdoorCallbackLogin = async () => {
|
||||
return true;
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
if (err.code === 'CASDOOR_USER_NOT_FOUND') {
|
||||
msg.error(t('workspace.msg.casdoorNotMatchedNeedLocalUser'));
|
||||
} else if (err.code === 'ACCOUNT_DISABLED') {
|
||||
msg.error(t('workspace.msg.localAccountDisabled'));
|
||||
} else {
|
||||
msg.error(err.message || 'Casdoor login failed');
|
||||
}
|
||||
console.error(e);
|
||||
msg.error(resolveCasdoorErrorMessage(err, t));
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
@@ -751,6 +734,7 @@ const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates
|
||||
const wsScheduleFilterInputClass = 'admin-table-filter-input text-xs py-1.5 px-2';
|
||||
const isProfileLoading = ref(false);
|
||||
const isProfileSaving = ref(false);
|
||||
const isChangingPassword = ref(false);
|
||||
const isProfileEditing = ref(false);
|
||||
const showPasswordModal = ref(false);
|
||||
|
||||
@@ -934,12 +918,15 @@ const saveProfile = async () => {
|
||||
};
|
||||
|
||||
const handleChangePassword = async () => {
|
||||
if (isChangingPassword.value) return;
|
||||
|
||||
if (passwordForm.value.new !== passwordForm.value.confirm) {
|
||||
msg.warning(t('profile.passwordMismatch') || 'Passwords do not match');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isChangingPassword.value = true;
|
||||
await requestJson('/api/user/change-password', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
@@ -953,7 +940,9 @@ const handleChangePassword = async () => {
|
||||
showPasswordModal.value = false;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error)?.message || t('workspace.profile.msg.changePasswordFailed'));
|
||||
msg.error(resolveCasdoorErrorMessage(e as BusinessError, t) || t('workspace.profile.msg.changePasswordFailed'));
|
||||
} finally {
|
||||
isChangingPassword.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2349,12 +2338,17 @@ onBeforeUnmount(() => {
|
||||
<div
|
||||
v-if="CHANGE_PASSWORD_ENABLED && showPasswordModal"
|
||||
class="dialog-overlay z-50 items-center"
|
||||
@click.self="showPasswordModal = false"
|
||||
>
|
||||
<div class="dialog-panel max-w-md">
|
||||
<div class="dialog-header">
|
||||
<h3 class="section-title">{{ $t('profile.changePassword') || 'Change Password' }}</h3>
|
||||
<button type="button" class="btn-icon-ds" :aria-label="$t('admin.close')" @click="showPasswordModal = false">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-icon-ds"
|
||||
:aria-label="$t('admin.close')"
|
||||
:disabled="isChangingPassword"
|
||||
@click="showPasswordModal = false"
|
||||
>
|
||||
<X class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -2362,23 +2356,50 @@ onBeforeUnmount(() => {
|
||||
<div class="dialog-body">
|
||||
<div>
|
||||
<label class="label-field">{{ $t('profile.currentPassword') || 'Current Password' }}</label>
|
||||
<input v-model="passwordForm.current" type="password" class="input-field mt-1" required />
|
||||
<input
|
||||
v-model="passwordForm.current"
|
||||
type="password"
|
||||
class="input-field mt-1"
|
||||
:disabled="isChangingPassword"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label-field">{{ $t('profile.newPassword') || 'New Password' }}</label>
|
||||
<input v-model="passwordForm.new" type="password" class="input-field mt-1" required />
|
||||
<input
|
||||
v-model="passwordForm.new"
|
||||
type="password"
|
||||
class="input-field mt-1"
|
||||
:disabled="isChangingPassword"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label-field">{{ $t('profile.confirmPassword') || 'Confirm Password' }}</label>
|
||||
<input v-model="passwordForm.confirm" type="password" class="input-field mt-1" required />
|
||||
<input
|
||||
v-model="passwordForm.confirm"
|
||||
type="password"
|
||||
class="input-field mt-1"
|
||||
:disabled="isChangingPassword"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" @click="showPasswordModal = false" class="btn-secondary flex-1">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="isChangingPassword"
|
||||
@click="showPasswordModal = false"
|
||||
class="btn-secondary flex-1 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{{ $t('profile.cancel') || 'Cancel' }}
|
||||
</button>
|
||||
<button type="submit" class="btn-primary flex-1">
|
||||
{{ $t('profile.changePassword') || 'Update' }}
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="isChangingPassword"
|
||||
class="btn-primary flex-1 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{{ isChangingPassword ? $t('profile.changingPassword') : ($t('profile.changePassword') || 'Update') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user