Fix admin UI password reset and user deletion functions.

This commit is contained in:
Leo Vasanko
2025-09-30 18:31:20 -06:00
parent cfc80d2462
commit b8816d482c
2 changed files with 32 additions and 5 deletions

View File

@@ -271,6 +271,18 @@ async def update_user(request, username):
return json(response) return json(response)
@bp.delete("/users/<username>")
async def delete_user(request, username):
verify(request, privileged=True)
if username not in config.config.users:
raise BadRequest("User does not exist")
try:
config.del_user(username)
except Exception as e:
raise BadRequest(str(e)) from e
return json({"message": f"User {username} deleted"})
@bp.put("/config/public") @bp.put("/config/public")
async def update_public(request): async def update_public(request):
verify(request, privileged=True) verify(request, privileged=True)

View File

@@ -14,9 +14,9 @@
</div> </div>
<h3>Users</h3> <h3>Users</h3>
<button @click="addUser" class="button" title="Add new user"> Add User</button> <button @click="addUser" class="button" title="Add new user"> Add User</button>
<div v-if="success" class="success-message"> <div v-if="success" class="success-message" @click="copySuccess(false)">
{{ success }} {{ success }}
<button @click="copySuccess" class="button small" title="Copy to clipboard"><EFBFBD></button> <button v-if="success.includes('Password:') || success.includes('New password:')" @click.stop="copySuccess(true)" class="button small" title="Copy to clipboard">{{ copyButtonText }}</button>
</div> </div>
<table class="user-table"> <table class="user-table">
<thead> <thead>
@@ -70,6 +70,7 @@ const loading = ref(true)
const users = ref<User[]>([]) const users = ref<User[]>([])
const error = ref('') const error = ref('')
const success = ref('') const success = ref('')
const copyButtonText = ref('📋')
const serverSettings = reactive({ const serverSettings = reactive({
public: false public: false
}) })
@@ -170,11 +171,25 @@ const deleteUserAction = async (username: string) => {
} }
} }
const copySuccess = async () => { const copySuccess = async (isButtonClick: boolean = false) => {
const passwordMatch = success.value.match(/Password: (.+)/) const passwordMatch = success.value.match(/(?:Password|New password): (.+)/)
if (passwordMatch) { if (passwordMatch) {
await navigator.clipboard.writeText(passwordMatch[1]) await navigator.clipboard.writeText(passwordMatch[1])
// Maybe flash or something, but for now just copy if (isButtonClick) {
// Show "Copied!" indication on button
copyButtonText.value = '✅ Copied!'
// Hide password and button immediately after copying
const baseMessage = success.value.replace(/(?:Password|New password): .+/, 'Password copied to clipboard!')
success.value = baseMessage
// Hide the entire message after 3 seconds
setTimeout(() => {
success.value = ''
copyButtonText.value = '📋'
}, 3000)
} else {
// Just hide the message when clicking elsewhere
success.value = ''
}
} }
} }