Add password resets
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Form v-if="!userData.authenticated" v-slot="$form" :initialValues @submit="onFormSubmit">
|
<Form v-if="!userData.authenticated" v-slot="$form" @submit="onFormSubmit">
|
||||||
<div class="flex flex-column">
|
<div class="flex flex-column">
|
||||||
<InputText name="username" type="text" placeholder="Username" fluid/>
|
<InputText name="username" type="text" placeholder="Username" fluid/>
|
||||||
<Password name="password" placeholder="Password" :feedback="false" fluid/>
|
<Password name="password" placeholder="Password" :feedback="false" fluid/>
|
||||||
@@ -8,7 +8,11 @@
|
|||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
<div v-if="userData.authenticated">
|
<div v-if="userData.authenticated">
|
||||||
<h2>Logged in as: {{userData.username}}</h2>
|
<h3>Logged in as: {{userData.username}}</h3>
|
||||||
|
<Form v-slot="$form" @submit="onResetPassword">
|
||||||
|
<Password name="password" placeholder="Password" :feedback="false" fluid/>
|
||||||
|
<Button type="submit" label="Reset Password" fluid/>
|
||||||
|
</Form>
|
||||||
<Button @click=logout() label="Log Out" fluid/>
|
<Button @click=logout() label="Log Out" fluid/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -25,24 +29,18 @@ import Password from 'primevue/password';
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
const userData = ref({
|
const userData = ref({
|
||||||
|
id: -1,
|
||||||
username: "NONE",
|
username: "NONE",
|
||||||
authenticated: false
|
authenticated: false
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
axios.get('/api/auth/user').then((resp) => {
|
axios.get('/api/auth/user').then((resp) => {
|
||||||
console.log(resp)
|
|
||||||
userData.value = resp.data
|
userData.value = resp.data
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialValues = reactive({
|
|
||||||
username: '',
|
|
||||||
password: ''
|
|
||||||
})
|
|
||||||
|
|
||||||
function onFormSubmit(form) {
|
function onFormSubmit(form) {
|
||||||
console.log(form)
|
|
||||||
const username = form.values.username
|
const username = form.values.username
|
||||||
const password = form.values.password
|
const password = form.values.password
|
||||||
|
|
||||||
@@ -51,6 +49,13 @@ function onFormSubmit(form) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onResetPassword(form) {
|
||||||
|
const username = userData.value.username
|
||||||
|
const password = form.values.password
|
||||||
|
|
||||||
|
axios.post(`/api/auth/user/${userData.value.id}`, {username, password});
|
||||||
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
axios.post('/api/auth/logout').then((resp) => {
|
axios.post('/api/auth/logout').then((resp) => {
|
||||||
userData.value = resp.data
|
userData.value = resp.data
|
||||||
|
|||||||
Reference in New Issue
Block a user