fix(password): 优化修改密码相关bug
This commit is contained in:
1 parent
3837a8669e
commit
1de4b78181
5 files changed
+344
-38
No files matched your search
@@ -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