diff --git a/package-lock.json b/package-lock.json index b2241f8..6b008bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "tailwind-merge": "^2.6.0", "tailwind-variants": "^0.3.1", "tailwindcss-animate": "^1.0.7", + "unique-names-generator": "^4.7.1", "vue": "^3.5.13", "vue-i18n": "^9.14.2", "vue-router": "^4.5.0", @@ -13819,6 +13820,15 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/unique-names-generator": { + "version": "4.7.1", + "resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-4.7.1.tgz", + "integrity": "sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/unique-slug": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/unique-slug/-/unique-slug-3.0.0.tgz", diff --git a/package.json b/package.json index d981e82..2c60f4f 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "tailwind-merge": "^2.6.0", "tailwind-variants": "^0.3.1", "tailwindcss-animate": "^1.0.7", + "unique-names-generator": "^4.7.1", "vue": "^3.5.13", "vue-i18n": "^9.14.2", "vue-router": "^4.5.0", diff --git a/src/components/demo/DemoAccountCreator.vue b/src/components/demo/DemoAccountCreator.vue new file mode 100644 index 0000000..ba64154 --- /dev/null +++ b/src/components/demo/DemoAccountCreator.vue @@ -0,0 +1,139 @@ + + + diff --git a/src/composables/useDemoAccountGenerator.ts b/src/composables/useDemoAccountGenerator.ts new file mode 100644 index 0000000..8c91562 --- /dev/null +++ b/src/composables/useDemoAccountGenerator.ts @@ -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(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 + } +} diff --git a/src/pages/LoginDemo.vue b/src/pages/LoginDemo.vue new file mode 100644 index 0000000..09de66c --- /dev/null +++ b/src/pages/LoginDemo.vue @@ -0,0 +1,148 @@ + + + diff --git a/src/router/index.ts b/src/router/index.ts index c5eb789..1517c63 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,7 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import { auth } from '@/composables/useAuth' import Home from '@/pages/Home.vue' -import Login from '@/pages/Login.vue' +import LoginDemo from '@/pages/LoginDemo.vue' const router = createRouter({ history: createWebHistory(), @@ -17,7 +17,7 @@ const router = createRouter({ { path: '/login', name: 'login', - component: Login, + component: LoginDemo, meta: { requiresAuth: false }