Renaming of users in registration, profile and admin app.
This commit is contained in:
@@ -364,6 +364,32 @@ async function toggleRolePermission(role, permId, checked) {
|
||||
function openDialog(type, data) { dialog.value = { type, data, busy: false, error: '' } }
|
||||
function closeDialog() { dialog.value = { type: null, data: null, busy: false, error: '' } }
|
||||
|
||||
// Admin user rename
|
||||
const editingUserName = ref(false)
|
||||
const editUserNameValue = ref('')
|
||||
const editUserNameValid = computed(()=> editUserNameValue.value.trim().length > 0 && editUserNameValue.value.trim().length <= 64)
|
||||
function beginEditUserName() {
|
||||
if (!selectedUser.value) return
|
||||
editingUserName.value = true
|
||||
editUserNameValue.value = userDetail.value?.display_name || selectedUser.value.display_name || ''
|
||||
}
|
||||
function cancelEditUserName() { editingUserName.value = false }
|
||||
async function submitEditUserName() {
|
||||
if (!editingUserName.value || !editUserNameValid.value) return
|
||||
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 data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Rename failed')
|
||||
editingUserName.value = false
|
||||
await loadOrgs()
|
||||
const r = await fetch(`/auth/admin/users/${selectedUser.value.uuid}`)
|
||||
const jd = await r.json(); if (!r.ok || jd.detail) throw new Error(jd.detail || 'Reload failed')
|
||||
userDetail.value = jd
|
||||
authStore.showMessage('User renamed', 'success', 1500)
|
||||
} catch (e) {
|
||||
authStore.showMessage(e.message || 'Rename failed')
|
||||
}
|
||||
}
|
||||
|
||||
async function submitDialog() {
|
||||
if (!dialog.value.type || dialog.value.busy) return
|
||||
dialog.value.busy = true; dialog.value.error = ''
|
||||
@@ -458,7 +484,14 @@ async function submitDialog() {
|
||||
|
||||
<!-- User Detail Page -->
|
||||
<div v-if="selectedUser" class="card user-detail">
|
||||
<h2 class="user-title"><span>{{ userDetail?.display_name || selectedUser.display_name }}</span></h2>
|
||||
<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-else>
|
||||
<input v-model="editUserNameValue" maxlength="64" @keyup.enter="submitEditUserName" />
|
||||
<button class="icon-btn" @click="submitEditUserName" :disabled="!editUserNameValid">💾</button>
|
||||
<button class="icon-btn" @click="cancelEditUserName">✖</button>
|
||||
</span>
|
||||
</h2>
|
||||
<div v-if="userDetail && !userDetail.error" class="user-meta">
|
||||
<p class="small">Organization: {{ userDetail.org.display_name }}</p>
|
||||
<p class="small">Role: {{ userDetail.role }}</p>
|
||||
|
||||
@@ -3,7 +3,15 @@
|
||||
<div class="view active">
|
||||
<h1>👋 Welcome! <a v-if="isAdmin" href="/auth/admin/" class="admin-link" title="Admin Console">Admin</a></h1>
|
||||
<div v-if="authStore.userInfo?.user" class="user-info">
|
||||
<h3>👤 {{ authStore.userInfo.user.user_name }}</h3>
|
||||
<h3>
|
||||
👤
|
||||
<template v-if="!editingName">{{ authStore.userInfo.user.user_name }} <button class="mini-btn" @click="startEdit" title="Edit name">✏️</button></template>
|
||||
<template v-else>
|
||||
<input v-model="newName" :disabled="authStore.isLoading" maxlength="64" @keyup.enter="saveName" />
|
||||
<button class="mini-btn" @click="saveName" :disabled="!validName || authStore.isLoading">💾</button>
|
||||
<button class="mini-btn" @click="cancelEdit" :disabled="authStore.isLoading">✖</button>
|
||||
</template>
|
||||
</h3>
|
||||
<span><strong>Visits:</strong></span>
|
||||
<span>{{ authStore.userInfo.user.visits || 0 }}</span>
|
||||
<span><strong>Registered:</strong></span>
|
||||
@@ -147,6 +155,25 @@ const logout = async () => {
|
||||
}
|
||||
|
||||
const isAdmin = computed(() => !!(authStore.userInfo?.is_global_admin || authStore.userInfo?.is_org_admin))
|
||||
|
||||
// Name editing state & actions
|
||||
const editingName = ref(false)
|
||||
const newName = ref('')
|
||||
const validName = computed(() => newName.value.trim().length > 0 && newName.value.trim().length <= 64)
|
||||
function startEdit() { editingName.value = true; newName.value = authStore.userInfo?.user?.user_name || '' }
|
||||
function cancelEdit() { editingName.value = false }
|
||||
async function saveName() {
|
||||
if (!validName.value) return
|
||||
try {
|
||||
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 data = await res.json(); if (!res.ok || data.detail) throw new Error(data.detail || 'Update failed')
|
||||
await authStore.loadUserInfo()
|
||||
editingName.value = false
|
||||
authStore.showMessage('Name updated', 'success', 1500)
|
||||
} catch (e) { authStore.showMessage(e.message || 'Failed to update name', 'error') }
|
||||
finally { authStore.isLoading = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -161,6 +188,7 @@ const isAdmin = computed(() => !!(authStore.userInfo?.is_global_admin || authSto
|
||||
.user-info span {
|
||||
text-align: left;
|
||||
}
|
||||
.mini-btn { font-size: 0.7em; margin-left: 0.3em; }
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -2,8 +2,17 @@
|
||||
<div class="container">
|
||||
<div class="view active">
|
||||
<h1>🔑 Add New Credential</h1>
|
||||
<h3>👤 {{ authStore.userInfo?.user?.user_name }}</h3>
|
||||
<!-- TODO: allow editing name <input type="text" v-model="user_name" required :disabled="authStore.isLoading"> -->
|
||||
<label class="name-edit">
|
||||
<span>👤 Name:</span>
|
||||
<input
|
||||
type="text"
|
||||
v-model="user_name"
|
||||
:placeholder="authStore.userInfo?.user?.user_name || 'Your name'"
|
||||
:disabled="authStore.isLoading"
|
||||
maxlength="64"
|
||||
@keyup.enter="register"
|
||||
/>
|
||||
</label>
|
||||
<p>Proceed to complete {{authStore.userInfo?.session_type}}:</p>
|
||||
<button
|
||||
class="btn-primary"
|
||||
@@ -19,15 +28,26 @@
|
||||
<script setup>
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import passkey from '@/utils/passkey'
|
||||
import { ref, watchEffect } from 'vue'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const user_name = ref('')
|
||||
|
||||
// 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() {
|
||||
authStore.isLoading = true
|
||||
authStore.showMessage('Starting registration...', 'info')
|
||||
|
||||
try {
|
||||
const result = await passkey.register(authStore.resetToken)
|
||||
const trimmed = (user_name.value || '').trim()
|
||||
const nameToSend = trimmed.length ? trimmed : null
|
||||
const result = await passkey.register(authStore.resetToken, nameToSend)
|
||||
console.log("Result", result)
|
||||
await authStore.setSessionCookie(result.session_token)
|
||||
// resetToken cleared by setSessionCookie; ensure again
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { startRegistration, startAuthentication } from '@simplewebauthn/browser'
|
||||
import aWebSocket from '@/utils/awaitable-websocket'
|
||||
|
||||
export async function register(resetToken = null) {
|
||||
const url = resetToken ? `/auth/ws/register?reset=${encodeURIComponent(resetToken)}` : "/auth/ws/register"
|
||||
export async function register(resetToken = null, displayName = null) {
|
||||
let params = []
|
||||
if (resetToken) params.push(`reset=${encodeURIComponent(resetToken)}`)
|
||||
if (displayName) params.push(`name=${encodeURIComponent(displayName)}`)
|
||||
const qs = params.length ? `?${params.join('&')}` : ''
|
||||
const url = `/auth/ws/register${qs}`
|
||||
const ws = await aWebSocket(url)
|
||||
try {
|
||||
const optionsJSON = await ws.receive_json()
|
||||
|
||||
Reference in New Issue
Block a user