User rename fixes.
This commit is contained in:
parent
37eaffff3f
commit
6d6c4ee35d
@ -367,17 +367,17 @@ function closeDialog() { dialog.value = { type: null, data: null, busy: false, e
|
|||||||
// Admin user rename
|
// Admin user rename
|
||||||
const editingUserName = ref(false)
|
const editingUserName = ref(false)
|
||||||
const editUserNameValue = ref('')
|
const editUserNameValue = ref('')
|
||||||
const editUserNameValid = computed(()=> editUserNameValue.value.trim().length > 0 && editUserNameValue.value.trim().length <= 64)
|
const editUserNameValid = computed(()=> true) // backend validates
|
||||||
function beginEditUserName() {
|
function beginEditUserName() {
|
||||||
if (!selectedUser.value) return
|
if (!selectedUser.value) return
|
||||||
editingUserName.value = true
|
editingUserName.value = true
|
||||||
editUserNameValue.value = userDetail.value?.display_name || selectedUser.value.display_name || ''
|
editUserNameValue.value = ''
|
||||||
}
|
}
|
||||||
function cancelEditUserName() { editingUserName.value = false }
|
function cancelEditUserName() { editingUserName.value = false }
|
||||||
async function submitEditUserName() {
|
async function submitEditUserName() {
|
||||||
if (!editingUserName.value || !editUserNameValid.value) return
|
if (!editingUserName.value) return
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/auth/admin/users/${selectedUser.value.uuid}/display-name`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: editUserNameValue.value.trim() }) })
|
const res = await fetch(`/auth/admin/users/${selectedUser.value.uuid}/display-name`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: editUserNameValue.value }) })
|
||||||
const data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Rename failed')
|
const data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Rename failed')
|
||||||
editingUserName.value = false
|
editingUserName.value = false
|
||||||
await loadOrgs()
|
await loadOrgs()
|
||||||
@ -487,8 +487,8 @@ async function submitDialog() {
|
|||||||
<h2 class="user-title">
|
<h2 class="user-title">
|
||||||
<span v-if="!editingUserName">{{ userDetail?.display_name || selectedUser.display_name }} <button class="icon-btn" @click="beginEditUserName" title="Rename user">✏️</button></span>
|
<span v-if="!editingUserName">{{ userDetail?.display_name || selectedUser.display_name }} <button class="icon-btn" @click="beginEditUserName" title="Rename user">✏️</button></span>
|
||||||
<span v-else>
|
<span v-else>
|
||||||
<input v-model="editUserNameValue" maxlength="64" @keyup.enter="submitEditUserName" />
|
<input v-model="editUserNameValue" :placeholder="userDetail?.display_name || selectedUser.display_name" maxlength="64" @keyup.enter="submitEditUserName" />
|
||||||
<button class="icon-btn" @click="submitEditUserName" :disabled="!editUserNameValid">💾</button>
|
<button class="icon-btn" @click="submitEditUserName">💾</button>
|
||||||
<button class="icon-btn" @click="cancelEditUserName">✖</button>
|
<button class="icon-btn" @click="cancelEditUserName">✖</button>
|
||||||
</span>
|
</span>
|
||||||
</h2>
|
</h2>
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
👤
|
👤
|
||||||
<template v-if="!editingName">{{ authStore.userInfo.user.user_name }} <button class="mini-btn" @click="startEdit" title="Edit name">✏️</button></template>
|
<template v-if="!editingName">{{ authStore.userInfo.user.user_name }} <button class="mini-btn" @click="startEdit" title="Edit name">✏️</button></template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<input v-model="newName" :disabled="authStore.isLoading" maxlength="64" @keyup.enter="saveName" />
|
<input v-model="newName" :placeholder="authStore.userInfo.user.user_name" :disabled="authStore.isLoading" maxlength="64" @keyup.enter="saveName" />
|
||||||
<button class="mini-btn" @click="saveName" :disabled="!validName || authStore.isLoading">💾</button>
|
<button class="mini-btn" @click="saveName" :disabled="authStore.isLoading">💾</button>
|
||||||
<button class="mini-btn" @click="cancelEdit" :disabled="authStore.isLoading">✖</button>
|
<button class="mini-btn" @click="cancelEdit" :disabled="authStore.isLoading">✖</button>
|
||||||
</template>
|
</template>
|
||||||
</h3>
|
</h3>
|
||||||
@ -159,14 +159,12 @@ const isAdmin = computed(() => !!(authStore.userInfo?.is_global_admin || authSto
|
|||||||
// Name editing state & actions
|
// Name editing state & actions
|
||||||
const editingName = ref(false)
|
const editingName = ref(false)
|
||||||
const newName = ref('')
|
const newName = ref('')
|
||||||
const validName = computed(() => newName.value.trim().length > 0 && newName.value.trim().length <= 64)
|
function startEdit() { editingName.value = true; newName.value = '' }
|
||||||
function startEdit() { editingName.value = true; newName.value = authStore.userInfo?.user?.user_name || '' }
|
|
||||||
function cancelEdit() { editingName.value = false }
|
function cancelEdit() { editingName.value = false }
|
||||||
async function saveName() {
|
async function saveName() {
|
||||||
if (!validName.value) return
|
|
||||||
try {
|
try {
|
||||||
authStore.isLoading = true
|
authStore.isLoading = true
|
||||||
const res = await fetch('/auth/user/display-name', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: newName.value.trim() }) })
|
const res = await fetch('/auth/user/display-name', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ display_name: newName.value }) })
|
||||||
const data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Update failed')
|
const data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Update failed')
|
||||||
await authStore.loadUserInfo()
|
await authStore.loadUserInfo()
|
||||||
editingName.value = false
|
editingName.value = false
|
||||||
|
@ -28,26 +28,17 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import passkey from '@/utils/passkey'
|
import passkey from '@/utils/passkey'
|
||||||
import { ref, watchEffect } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const user_name = ref('')
|
const user_name = ref('') // intentionally blank; original shown via placeholder
|
||||||
|
|
||||||
// Initialize local name from store (once loaded)
|
|
||||||
watchEffect(() => {
|
|
||||||
if (!user_name.value && authStore.userInfo?.user?.user_name) {
|
|
||||||
user_name.value = authStore.userInfo.user.user_name
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
async function register() {
|
async function register() {
|
||||||
authStore.isLoading = true
|
authStore.isLoading = true
|
||||||
authStore.showMessage('Starting registration...', 'info')
|
authStore.showMessage('Starting registration...', 'info')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const trimmed = (user_name.value || '').trim()
|
const result = await passkey.register(authStore.resetToken, user_name.value)
|
||||||
const nameToSend = trimmed.length ? trimmed : null
|
|
||||||
const result = await passkey.register(authStore.resetToken, nameToSend)
|
|
||||||
console.log("Result", result)
|
console.log("Result", result)
|
||||||
await authStore.setSessionCookie(result.session_token)
|
await authStore.setSessionCookie(result.session_token)
|
||||||
// resetToken cleared by setSessionCookie; ensure again
|
// resetToken cleared by setSessionCookie; ensure again
|
||||||
|
Loading…
x
Reference in New Issue
Block a user