Skip to content

Commit

Permalink
add password create logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Mar 22, 2024
1 parent 65b3b91 commit d2affe4
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/Frontend/src/components/UserAddForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@ const emit = defineEmits
<{(e: 'close'): void
}>()
const isPassword = ref(true)
const form = ref<UserAdd>({})
async function create () {
if (await apiHelper.createUser(form.value)) {
emit('close')
}
}
function createPassword () {
const length = 20
const allowedCharacters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+!@-#.'
const randomPassword = Array.from(crypto.getRandomValues(new Uint32Array(length)))
.map((x) => allowedCharacters[x % allowedCharacters.length])
.join('')
form.value.password = randomPassword
}
</script>
<template>
Expand All @@ -30,10 +43,29 @@ async function create () {
/>
<q-input
v-model="form.password"
type="password"
:type="isPassword ? 'password' : 'text'"
label="Password"
outlined
/>
>
<template #append>
<q-icon
:name="isPassword ? 'visibility_off' : 'visibility'"
class="cursor-pointer"
@click="isPassword = !isPassword"
/>
</template>
<template #after>
<q-btn
dense
stretch
flat
icon="password"
title="Create random password"
@click="createPassword"
/>
</template>
</q-input>
<q-input
v-model="form.firstname"
label="Firstname"
Expand Down

0 comments on commit d2affe4

Please sign in to comment.