feat: Add demo account creation functionality

- Introduce a new DemoAccountCreator component for generating test accounts with auto-generated credentials.
- Implement useDemoAccountGenerator composable to handle credential generation and state management.
- Update routing to replace the existing login page with the new LoginDemo page for demo account access.
- Add unique-names-generator package to facilitate username generation.
This commit is contained in:
padreug 2025-09-01 21:00:29 +02:00
parent bc73871c82
commit 320e322db2
6 changed files with 365 additions and 2 deletions

View file

@ -0,0 +1,65 @@
import { ref } from 'vue'
import { uniqueNamesGenerator, names, colors, animals } from 'unique-names-generator'
export interface GeneratedCredentials {
username: string
password: string
email: string
}
export function useDemoAccountGenerator() {
const isLoading = ref(false)
const error = ref('')
const generatedCredentials = ref<GeneratedCredentials | null>(null)
// Generate a random password
function generateRandomPassword(): string {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*'
let password = ''
for (let i = 0; i < 12; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length))
}
return password
}
// Generate unique username and random password
function generateCredentials(): GeneratedCredentials {
// Use only 2 dictionaries to keep username shorter
const username = uniqueNamesGenerator({
dictionaries: [names, colors],
separator: '_',
length: 2,
style: 'lowerCase'
})
const password = generateRandomPassword()
const email = `${username}@demo.local`
return { username, password, email }
}
// Generate new credentials
function generateNewCredentials(): GeneratedCredentials {
const credentials = generateCredentials()
generatedCredentials.value = credentials
return credentials
}
// Reset state
function reset() {
isLoading.value = false
error.value = ''
generatedCredentials.value = null
}
return {
// State
isLoading,
error,
generatedCredentials,
// Actions
generateCredentials,
generateNewCredentials,
reset
}
}