feat: 收官补齐全部未实现功能
- 账号体系:修改密码(/account + PATCH /api/auth/password)、自助删除账号 (DELETE /api/auth/me)、订阅退订(token + /unsubscribe 页) - 前台/SEO:RSS 订阅 /feed.xml、作品详情分享、canonical URL、 文章 Article JSON-LD、品牌化错误页(i18n) - 后台增强:图片管理 /admin/uploads、操作审计日志 /admin/audit(含清空)、 联系消息已读标记、评论列表分页 - 工程:vitest 测试(密码哈希/内容校验器/种子完整性,12 例)+ pnpm test - DB 迁移:contacts.read、subscribers.token、audit_logs(老库 ALTER 兼容) - 密码逻辑抽为 server/utils/password.ts 供测试
This commit is contained in:
@@ -87,6 +87,72 @@
|
||||
{{ saving ? t('account.saving') : t('account.save') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 修改密码 -->
|
||||
<form class="p-6 rounded-2xl bg-white border border-gray-100 shadow-sm space-y-5" @submit.prevent="changePassword">
|
||||
<h3 class="text-lg font-bold text-black">{{ t('account.changePassword.title') }}</h3>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-2">{{ t('account.changePassword.currentPassword') }}</label>
|
||||
<input
|
||||
v-model="pwForm.currentPassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-2">{{ t('account.changePassword.newPassword') }}</label>
|
||||
<input
|
||||
v-model="pwForm.newPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-2">{{ t('account.changePassword.confirmPassword') }}</label>
|
||||
<input
|
||||
v-model="pwForm.confirmPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="pwMessage" class="text-sm" :class="pwFailed ? 'text-red-600' : 'text-green-600'">{{ pwMessage }}</p>
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="pwSaving"
|
||||
class="w-full py-3 rounded-xl bg-black text-white font-semibold flex items-center justify-center gap-2 transition-colors disabled:opacity-50"
|
||||
>
|
||||
<Icon v-if="pwSaving" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
|
||||
{{ pwSaving ? t('account.changePassword.saving') : t('account.changePassword.submit') }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- 删除账号(危险区) -->
|
||||
<div class="p-6 rounded-2xl bg-white border border-red-200 shadow-sm space-y-5">
|
||||
<h3 class="text-lg font-bold text-red-600">{{ t('account.deleteAccount.title') }}</h3>
|
||||
<p class="text-sm text-gray-500">{{ t('account.deleteAccount.hint') }}</p>
|
||||
<div>
|
||||
<input
|
||||
v-model="deletePassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
:placeholder="t('account.deleteAccount.passwordPlaceholder')"
|
||||
@keydown.enter.prevent
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-red-500 focus:ring-2 focus:ring-red-500/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="deleteMessage" class="text-sm" :class="deleteFailed ? 'text-red-600' : 'text-green-600'">{{ deleteMessage }}</p>
|
||||
<button
|
||||
@click="confirmDeleteAccount"
|
||||
:disabled="deleting"
|
||||
class="w-full py-3 rounded-xl bg-red-600 text-white font-semibold flex items-center justify-center gap-2 transition-colors hover:bg-red-700 disabled:opacity-50"
|
||||
>
|
||||
<Icon v-if="deleting" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
|
||||
{{ t('account.deleteAccount.confirmButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 我的收藏 -->
|
||||
@@ -211,6 +277,72 @@ const saveProfile = async () => {
|
||||
saving.value = false
|
||||
}
|
||||
|
||||
// ---- 修改密码 ----
|
||||
const pwForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' })
|
||||
const pwSaving = ref(false)
|
||||
const pwMessage = ref('')
|
||||
const pwFailed = ref(false)
|
||||
|
||||
const changePassword = async () => {
|
||||
pwMessage.value = ''
|
||||
pwFailed.value = false
|
||||
|
||||
if (pwForm.newPassword.length < 8) {
|
||||
pwFailed.value = true
|
||||
pwMessage.value = t('account.changePassword.tooShort')
|
||||
return
|
||||
}
|
||||
if (pwForm.newPassword !== pwForm.confirmPassword) {
|
||||
pwFailed.value = true
|
||||
pwMessage.value = t('account.changePassword.mismatch')
|
||||
return
|
||||
}
|
||||
|
||||
pwSaving.value = true
|
||||
try {
|
||||
await $fetch('/api/auth/password', {
|
||||
method: 'PATCH',
|
||||
body: { currentPassword: pwForm.currentPassword, newPassword: pwForm.newPassword },
|
||||
})
|
||||
pwMessage.value = t('account.changePassword.success')
|
||||
pwForm.currentPassword = ''
|
||||
pwForm.newPassword = ''
|
||||
pwForm.confirmPassword = ''
|
||||
} catch (err) {
|
||||
pwFailed.value = true
|
||||
pwMessage.value =
|
||||
(err as any)?.data?.code === 'WRONG_PASSWORD'
|
||||
? t('account.changePassword.wrongPassword')
|
||||
: apiError(err)
|
||||
}
|
||||
pwSaving.value = false
|
||||
}
|
||||
|
||||
// ---- 删除账号 ----
|
||||
const deletePassword = ref('')
|
||||
const deleting = ref(false)
|
||||
const deleteMessage = ref('')
|
||||
const deleteFailed = ref(false)
|
||||
|
||||
const confirmDeleteAccount = async () => {
|
||||
if (!window.confirm(t('account.deleteAccount.confirmText'))) return
|
||||
deleteMessage.value = ''
|
||||
deleteFailed.value = false
|
||||
deleting.value = true
|
||||
try {
|
||||
await $fetch('/api/auth/me', { method: 'DELETE', body: { password: deletePassword.value } })
|
||||
await userStore.logout()
|
||||
await navigateTo('/')
|
||||
} catch (err) {
|
||||
deleteFailed.value = true
|
||||
deleteMessage.value =
|
||||
(err as any)?.data?.code === 'WRONG_PASSWORD'
|
||||
? t('account.deleteAccount.wrongPassword')
|
||||
: apiError(err)
|
||||
}
|
||||
deleting.value = false
|
||||
}
|
||||
|
||||
// ---- 收藏 ----
|
||||
interface FavedWork { slug: string; titleZh: string; titleEn: string; image: string | null }
|
||||
const favorites = ref<FavedWork[]>([])
|
||||
|
||||
Reference in New Issue
Block a user