v01
This commit is contained in:
@@ -1,19 +1,33 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="setup-container">
|
||||
<h2>Setup Admin Account</h2>
|
||||
<form @submit.prevent="setup">
|
||||
<input v-model="form.login" placeholder="Admin login" />
|
||||
<input v-model="form.password" type="password" placeholder="Password (min 6 chars)" />
|
||||
<div>
|
||||
<input
|
||||
v-model="form.login"
|
||||
placeholder="Admin login (min 3 chars)"
|
||||
required
|
||||
minlength="3"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<input
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
placeholder="Password (min 6 chars)"
|
||||
required
|
||||
minlength="6"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit">Create Admin</button>
|
||||
</form>
|
||||
<p v-if="error">{{ error }}</p>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import axios from 'axios'
|
||||
|
||||
const router = useRouter()
|
||||
const form = ref({ login: '', password: '' })
|
||||
@@ -21,10 +35,41 @@ const error = ref('')
|
||||
|
||||
async function setup() {
|
||||
try {
|
||||
await axios.post('/api/setup', form.value)
|
||||
router.push('/login')
|
||||
const res = await fetch('/api/setup', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form.value)
|
||||
})
|
||||
|
||||
const data = await res.json()
|
||||
|
||||
if (res.ok) {
|
||||
router.push('/login')
|
||||
} else {
|
||||
error.value = data.error || 'Setup failed'
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e.response?.data || 'Setup failed'
|
||||
error.value = 'Network error'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.setup-container {
|
||||
max-width: 300px;
|
||||
margin: 100px auto;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
margin: 5px 0;
|
||||
}
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.error {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user