feat(system): add admin password reset with session revocation
Let system administrators reset another user's local password from the settings UI, revoke all active sessions, and record the action in the audit log.
This commit is contained in:
@@ -320,6 +320,21 @@ export async function listSystemAdmins(
|
||||
return response as unknown as ListSystemAdminsResponse
|
||||
}
|
||||
|
||||
export interface ResetUserPasswordRequest {
|
||||
email: string
|
||||
new_password: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace another user's password and revoke all of their active sessions.
|
||||
* The backend route is restricted to SystemAdmin callers and rejects attempts
|
||||
* to reset the caller's own password.
|
||||
*/
|
||||
export async function resetUserPassword(req: ResetUserPasswordRequest): Promise<{ message: string }> {
|
||||
const response = await post('/api/v1/system/admin/users/reset-password', req)
|
||||
return response as unknown as { message: string }
|
||||
}
|
||||
|
||||
// ---- System Settings (P1) ----
|
||||
|
||||
/**
|
||||
|
||||
@@ -3768,6 +3768,32 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
passwordReset: {
|
||||
label: 'Reset user password',
|
||||
description: 'Set a new password for another user who cannot sign in. A successful reset invalidates all of that user\'s current sessions, so they must sign in again with the new password.',
|
||||
action: 'Reset password',
|
||||
dialogTitle: 'Reset another user\'s password',
|
||||
warning: 'This is a high-risk action. Verify the user email carefully. You cannot reset your own password here.',
|
||||
emailLabel: 'User email',
|
||||
emailPlaceholder: 'Enter the email of the user to reset',
|
||||
newPasswordLabel: 'New password',
|
||||
newPasswordPlaceholder: '8-32 characters, including letters and numbers',
|
||||
confirmPasswordLabel: 'Confirm new password',
|
||||
confirmPasswordPlaceholder: 'Enter the new password again',
|
||||
confirmBtn: 'Confirm reset',
|
||||
success: 'Password reset; the user\'s existing sessions were revoked',
|
||||
failed: 'Failed to reset password',
|
||||
validation: {
|
||||
emailRequired: 'Enter the user email',
|
||||
emailInvalid: 'Enter a valid email address',
|
||||
passwordRequired: 'Enter a new password',
|
||||
passwordLength: 'Password must be 8-32 characters',
|
||||
passwordLetter: 'Password must contain a letter',
|
||||
passwordNumber: 'Password must contain a number',
|
||||
confirmRequired: 'Enter the new password again',
|
||||
passwordMismatch: 'The passwords do not match',
|
||||
},
|
||||
},
|
||||
bulkApply: {
|
||||
label: 'Apply to all existing tenants',
|
||||
tooltip: 'Saving the value only affects new tenants by default; click here to also overwrite every existing tenant.',
|
||||
@@ -3805,6 +3831,7 @@ export default {
|
||||
'system.setting_changed': 'System setting changed',
|
||||
'system.admin_promoted': 'System admin granted',
|
||||
'system.admin_revoked': 'System admin revoked',
|
||||
'system.user_password_reset': 'User password reset',
|
||||
},
|
||||
outcome: {
|
||||
success: 'Success',
|
||||
|
||||
@@ -2753,6 +2753,32 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
passwordReset: {
|
||||
label: "사용자 비밀번호 재설정",
|
||||
description: "로그인할 수 없는 다른 사용자의 새 비밀번호를 설정합니다. 재설정하면 해당 사용자의 현재 로그인 세션이 모두 만료되며 새 비밀번호로 다시 로그인해야 합니다.",
|
||||
action: "비밀번호 재설정",
|
||||
dialogTitle: "다른 사용자의 비밀번호 재설정",
|
||||
warning: "보안에 민감한 작업입니다. 사용자 이메일을 반드시 확인하세요. 여기서는 자신의 비밀번호를 재설정할 수 없습니다.",
|
||||
emailLabel: "사용자 이메일",
|
||||
emailPlaceholder: "비밀번호를 재설정할 사용자의 이메일 입력",
|
||||
newPasswordLabel: "새 비밀번호",
|
||||
newPasswordPlaceholder: "8~32자, 문자와 숫자 포함",
|
||||
confirmPasswordLabel: "새 비밀번호 확인",
|
||||
confirmPasswordPlaceholder: "새 비밀번호를 다시 입력",
|
||||
confirmBtn: "재설정 확인",
|
||||
success: "비밀번호가 재설정되고 기존 세션이 만료되었습니다",
|
||||
failed: "비밀번호 재설정 실패",
|
||||
validation: {
|
||||
emailRequired: "사용자 이메일을 입력하세요",
|
||||
emailInvalid: "올바른 이메일 주소를 입력하세요",
|
||||
passwordRequired: "새 비밀번호를 입력하세요",
|
||||
passwordLength: "비밀번호는 8~32자여야 합니다",
|
||||
passwordLetter: "비밀번호에 문자가 포함되어야 합니다",
|
||||
passwordNumber: "비밀번호에 숫자가 포함되어야 합니다",
|
||||
confirmRequired: "새 비밀번호를 다시 입력하세요",
|
||||
passwordMismatch: "비밀번호가 일치하지 않습니다",
|
||||
},
|
||||
},
|
||||
bulkApply: {
|
||||
label: "모든 기존 테넌트에 적용",
|
||||
tooltip: "저장한 값은 기본적으로 새로 생성되는 테넌트에만 적용됩니다. 이 버튼을 누르면 현재 값을 모든 기존 테넌트에도 덮어씁니다.",
|
||||
@@ -2790,6 +2816,7 @@ export default {
|
||||
"system.setting_changed": "시스템 설정 변경",
|
||||
"system.admin_promoted": "시스템 관리자 부여",
|
||||
"system.admin_revoked": "시스템 관리자 회수",
|
||||
"system.user_password_reset": "사용자 비밀번호 재설정",
|
||||
},
|
||||
outcome: {
|
||||
success: "성공",
|
||||
|
||||
@@ -2451,6 +2451,32 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
passwordReset: {
|
||||
label: 'Сброс пароля пользователя',
|
||||
description: 'Задайте новый пароль другому пользователю, который не может войти. После сброса все его текущие сеансы будут завершены, и потребуется войти с новым паролем.',
|
||||
action: 'Сбросить пароль',
|
||||
dialogTitle: 'Сброс пароля другого пользователя',
|
||||
warning: 'Это операция повышенного риска. Внимательно проверьте email пользователя. Здесь нельзя сбросить собственный пароль.',
|
||||
emailLabel: 'Email пользователя',
|
||||
emailPlaceholder: 'Введите email пользователя',
|
||||
newPasswordLabel: 'Новый пароль',
|
||||
newPasswordPlaceholder: '8–32 символа, включая буквы и цифры',
|
||||
confirmPasswordLabel: 'Подтвердите новый пароль',
|
||||
confirmPasswordPlaceholder: 'Введите новый пароль ещё раз',
|
||||
confirmBtn: 'Подтвердить сброс',
|
||||
success: 'Пароль сброшен, существующие сеансы пользователя завершены',
|
||||
failed: 'Не удалось сбросить пароль',
|
||||
validation: {
|
||||
emailRequired: 'Введите email пользователя',
|
||||
emailInvalid: 'Введите корректный email',
|
||||
passwordRequired: 'Введите новый пароль',
|
||||
passwordLength: 'Пароль должен содержать от 8 до 32 символов',
|
||||
passwordLetter: 'Пароль должен содержать букву',
|
||||
passwordNumber: 'Пароль должен содержать цифру',
|
||||
confirmRequired: 'Введите новый пароль ещё раз',
|
||||
passwordMismatch: 'Пароли не совпадают',
|
||||
},
|
||||
},
|
||||
bulkApply: {
|
||||
label: 'Применить ко всем существующим тенантам',
|
||||
tooltip: 'По умолчанию сохранённое значение применяется только к новым тенантам. Нажмите, чтобы также перезаписать всех существующих.',
|
||||
@@ -2487,7 +2513,8 @@ export default {
|
||||
action: {
|
||||
'system.setting_changed': 'Изменена системная настройка',
|
||||
'system.admin_promoted': 'Выдан системный администратор',
|
||||
'system.admin_revoked': 'Отозван системный администратор'
|
||||
'system.admin_revoked': 'Отозван системный администратор',
|
||||
'system.user_password_reset': 'Сброшен пароль пользователя'
|
||||
},
|
||||
outcome: {
|
||||
success: 'Успешно',
|
||||
|
||||
@@ -2767,6 +2767,32 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
passwordReset: {
|
||||
label: "重置用户密码",
|
||||
description: "为忘记密码的其他用户设置新密码。重置成功后,该用户当前所有登录会话都会失效,需要使用新密码重新登录。",
|
||||
action: "重置密码",
|
||||
dialogTitle: "重置其他用户的密码",
|
||||
warning: "这是高风险操作。请核对用户邮箱;出于安全考虑,不能在这里重置自己的密码。",
|
||||
emailLabel: "用户邮箱",
|
||||
emailPlaceholder: "输入需要重置密码的用户邮箱",
|
||||
newPasswordLabel: "新密码",
|
||||
newPasswordPlaceholder: "8-32 个字符,包含字母和数字",
|
||||
confirmPasswordLabel: "确认新密码",
|
||||
confirmPasswordPlaceholder: "再次输入新密码",
|
||||
confirmBtn: "确认重置",
|
||||
success: "密码已重置,该用户的现有会话已失效",
|
||||
failed: "重置密码失败",
|
||||
validation: {
|
||||
emailRequired: "请输入用户邮箱",
|
||||
emailInvalid: "请输入有效的邮箱地址",
|
||||
passwordRequired: "请输入新密码",
|
||||
passwordLength: "密码长度必须为 8-32 个字符",
|
||||
passwordLetter: "密码必须包含字母",
|
||||
passwordNumber: "密码必须包含数字",
|
||||
confirmRequired: "请再次输入新密码",
|
||||
passwordMismatch: "两次输入的密码不一致",
|
||||
},
|
||||
},
|
||||
bulkApply: {
|
||||
label: "应用到所有现有租户",
|
||||
tooltip: "保存的值默认只对之后新建的租户生效;点击此按钮将当前值同步写入所有现有租户。",
|
||||
@@ -2804,6 +2830,7 @@ export default {
|
||||
"system.setting_changed": "系统设置变更",
|
||||
"system.admin_promoted": "授予系统管理员",
|
||||
"system.admin_revoked": "回收系统管理员",
|
||||
"system.user_password_reset": "重置用户密码",
|
||||
},
|
||||
outcome: {
|
||||
success: "成功",
|
||||
|
||||
@@ -189,6 +189,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="activeSettingsSection === 'access'" class="setting-row setting-row--password-reset">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label">
|
||||
<span>{{ t('system.globalSettings.passwordReset.label') }}</span>
|
||||
<t-tag theme="danger" variant="light" size="small" class="setting-badge">
|
||||
{{ t('system.globalSettings.badgeHighRisk') }}
|
||||
</t-tag>
|
||||
</div>
|
||||
<p class="desc">{{ t('system.globalSettings.passwordReset.description') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-button theme="primary" variant="outline" @click="openPasswordResetDialog">
|
||||
<template #icon><t-icon name="lock-on" /></template>
|
||||
{{ t('system.globalSettings.passwordReset.action') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="item in activeSectionSettings"
|
||||
:key="item.key"
|
||||
@@ -422,6 +440,68 @@
|
||||
<div class="sr-only" role="status" aria-live="polite">{{ saveAnnouncement }}</div>
|
||||
</template>
|
||||
|
||||
<t-dialog
|
||||
v-model:visible="passwordResetVisible"
|
||||
:header="t('system.globalSettings.passwordReset.dialogTitle')"
|
||||
width="460px"
|
||||
:confirm-btn="{
|
||||
content: t('system.globalSettings.passwordReset.confirmBtn'),
|
||||
theme: 'danger',
|
||||
loading: passwordResetSubmitting,
|
||||
}"
|
||||
:cancel-btn="t('system.globalSettings.confirm.cancelBtn')"
|
||||
:close-on-overlay-click="!passwordResetSubmitting"
|
||||
:close-btn="!passwordResetSubmitting"
|
||||
@confirm="submitPasswordReset"
|
||||
@close="resetPasswordResetForm"
|
||||
>
|
||||
<t-alert
|
||||
theme="warning"
|
||||
:message="t('system.globalSettings.passwordReset.warning')"
|
||||
class="password-reset-warning"
|
||||
/>
|
||||
<t-form
|
||||
ref="passwordResetFormRef"
|
||||
:data="passwordResetForm"
|
||||
:rules="passwordResetRules"
|
||||
label-align="top"
|
||||
>
|
||||
<t-form-item :label="t('system.globalSettings.passwordReset.emailLabel')" name="email">
|
||||
<t-input
|
||||
v-model="passwordResetForm.email"
|
||||
type="email"
|
||||
clearable
|
||||
autocomplete="off"
|
||||
:disabled="passwordResetSubmitting"
|
||||
:placeholder="t('system.globalSettings.passwordReset.emailPlaceholder')"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item :label="t('system.globalSettings.passwordReset.newPasswordLabel')" name="newPassword">
|
||||
<t-input
|
||||
v-model="passwordResetForm.newPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:disabled="passwordResetSubmitting"
|
||||
:placeholder="t('system.globalSettings.passwordReset.newPasswordPlaceholder')"
|
||||
>
|
||||
<template #prefix-icon><t-icon name="lock-on" /></template>
|
||||
</t-input>
|
||||
</t-form-item>
|
||||
<t-form-item :label="t('system.globalSettings.passwordReset.confirmPasswordLabel')" name="confirmPassword">
|
||||
<t-input
|
||||
v-model="passwordResetForm.confirmPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:disabled="passwordResetSubmitting"
|
||||
:placeholder="t('system.globalSettings.passwordReset.confirmPasswordPlaceholder')"
|
||||
@enter="submitPasswordReset"
|
||||
>
|
||||
<template #prefix-icon><t-icon name="lock-on" /></template>
|
||||
</t-input>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-dialog>
|
||||
|
||||
<!-- Platform audit-log drawer. Lazy-loaded on first open; closing
|
||||
and reopening doesn't re-fetch (refresh is explicit via the
|
||||
button inside the drawer). Backend route is SystemAdmin-gated,
|
||||
@@ -568,6 +648,7 @@
|
||||
import { ref, reactive, onMounted, onUnmounted, computed, nextTick, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import type { FormInstanceFunctions, FormRule } from 'tdesign-vue-next'
|
||||
import {
|
||||
listSystemSettings,
|
||||
updateSystemSetting,
|
||||
@@ -576,6 +657,7 @@ import {
|
||||
listSystemAdmins,
|
||||
promoteUserToSystemAdmin,
|
||||
revokeSystemAdmin,
|
||||
resetUserPassword,
|
||||
listSystemAuditLog,
|
||||
type SystemSettingItem,
|
||||
type AuditLog,
|
||||
@@ -759,7 +841,7 @@ const restartRequiredCount = computed(() => settings.value.filter((item) => item
|
||||
function sectionTabLabel(section: SettingsSection): string {
|
||||
const count = section === 'other'
|
||||
? unknownSettings.value.length
|
||||
: SETTINGS_SECTION_KEYS[section].filter((key) => settingsByKey.value.has(key)).length + (section === 'access' ? 1 : 0)
|
||||
: SETTINGS_SECTION_KEYS[section].filter((key) => settingsByKey.value.has(key)).length + (section === 'access' ? 2 : 0)
|
||||
return t(`system.globalSettings.sections.${section}.tab`, { count })
|
||||
}
|
||||
|
||||
@@ -788,6 +870,73 @@ const adminEmails = ref<string[]>([])
|
||||
const adminEmailToId = ref<Record<string, string>>({})
|
||||
const adminBusy = ref(false)
|
||||
|
||||
const passwordResetVisible = ref(false)
|
||||
const passwordResetSubmitting = ref(false)
|
||||
const passwordResetFormRef = ref<FormInstanceFunctions>()
|
||||
const passwordResetForm = reactive({
|
||||
email: '',
|
||||
newPassword: '',
|
||||
confirmPassword: '',
|
||||
})
|
||||
const passwordResetRules: Record<string, FormRule[]> = {
|
||||
email: [
|
||||
{ required: true, message: t('system.globalSettings.passwordReset.validation.emailRequired'), trigger: 'blur' },
|
||||
{ email: true, message: t('system.globalSettings.passwordReset.validation.emailInvalid'), trigger: 'blur' },
|
||||
],
|
||||
newPassword: [
|
||||
{ required: true, message: t('system.globalSettings.passwordReset.validation.passwordRequired'), trigger: 'blur' },
|
||||
{ min: 8, message: t('system.globalSettings.passwordReset.validation.passwordLength'), trigger: 'blur' },
|
||||
{ max: 32, message: t('system.globalSettings.passwordReset.validation.passwordLength'), trigger: 'blur' },
|
||||
{ pattern: /[a-zA-Z]/, message: t('system.globalSettings.passwordReset.validation.passwordLetter'), trigger: 'blur' },
|
||||
{ pattern: /\d/, message: t('system.globalSettings.passwordReset.validation.passwordNumber'), trigger: 'blur' },
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: t('system.globalSettings.passwordReset.validation.confirmRequired'), trigger: 'blur' },
|
||||
{
|
||||
validator: (value: string) => value === passwordResetForm.newPassword,
|
||||
message: t('system.globalSettings.passwordReset.validation.passwordMismatch'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
function resetPasswordResetForm() {
|
||||
passwordResetForm.email = ''
|
||||
passwordResetForm.newPassword = ''
|
||||
passwordResetForm.confirmPassword = ''
|
||||
passwordResetFormRef.value?.clearValidate?.()
|
||||
}
|
||||
|
||||
async function openPasswordResetDialog() {
|
||||
resetPasswordResetForm()
|
||||
passwordResetVisible.value = true
|
||||
await nextTick()
|
||||
passwordResetFormRef.value?.clearValidate?.()
|
||||
}
|
||||
|
||||
async function submitPasswordReset() {
|
||||
if (passwordResetSubmitting.value) return
|
||||
const valid = await passwordResetFormRef.value?.validate?.()
|
||||
if (valid !== true) return
|
||||
|
||||
passwordResetSubmitting.value = true
|
||||
try {
|
||||
await resetUserPassword({
|
||||
email: passwordResetForm.email.trim(),
|
||||
new_password: passwordResetForm.newPassword,
|
||||
})
|
||||
saveAnnouncement.value = t('system.globalSettings.passwordReset.success')
|
||||
MessagePlugin.success(t('system.globalSettings.passwordReset.success'))
|
||||
passwordResetVisible.value = false
|
||||
} catch (err: any) {
|
||||
const msg = err?.message || t('system.globalSettings.passwordReset.failed')
|
||||
saveAnnouncement.value = msg
|
||||
MessagePlugin.error(msg)
|
||||
} finally {
|
||||
passwordResetSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Guards ssrf.whitelist while an async confirm roundtrip is in flight.
|
||||
const listConfirmBusyKey = ref<string | null>(null)
|
||||
|
||||
@@ -1393,6 +1542,8 @@ function auditActionTheme(
|
||||
case 'system.admin_revoked':
|
||||
case 'system.setting_changed':
|
||||
return 'warning'
|
||||
case 'system.user_password_reset':
|
||||
return 'danger'
|
||||
case 'rbac.access_denied':
|
||||
return 'danger'
|
||||
default:
|
||||
@@ -1459,7 +1610,11 @@ function auditTargetKey(row: AuditLog): string {
|
||||
if (details && typeof details.key === 'string' && details.key) return details.key
|
||||
return row.target_id || row.target_type || ''
|
||||
}
|
||||
if (row.action === 'system.admin_promoted' || row.action === 'system.admin_revoked') {
|
||||
if (
|
||||
row.action === 'system.admin_promoted'
|
||||
|| row.action === 'system.admin_revoked'
|
||||
|| row.action === 'system.user_password_reset'
|
||||
) {
|
||||
if (!details) return row.target_user_id ? row.target_user_id.slice(0, 8) : ''
|
||||
const name = typeof details.target_username === 'string' ? details.target_username : ''
|
||||
const mail = typeof details.target_email === 'string' ? details.target_email : ''
|
||||
@@ -2339,6 +2494,10 @@ onUnmounted(() => {
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
.password-reset-warning {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.settings-overview,
|
||||
.settings-section-intro {
|
||||
|
||||
Reference in New Issue
Block a user