@ -5,116 +5,126 @@
< PanelHeadTitle :text ="$t('pages.me')" / >
< PanelHeadTitle :text ="$t('pages.me')" / >
< / PanelHead >
< / PanelHead >
< PanelBody class = "dark:text-neutral-200" >
< PanelBody class = "dark:text-neutral-200" >
< section class = "grid grid-cols-1 gap-4 md:grid-cols-2" >
< FormElement @submit.prevent ="submit" >
< h4 class = "col-span-full py-6 text-2xl" >
< FormGroup >
{ { $t ( 'me.sectionGeneral' ) } }
< FormHeading > { { $t ( 'me.sectionGeneral' ) } } < / FormHeading >
< / h4 >
< FormTextField id = "name" v -model = " name " :label ="$t('name')" / >
< Label
< FormTextField id = "email" v -model = " email " :label ="$t('email')" / >
for = "username"
< FormActionField type = "submit" :label ="$t('save')" / >
class = "font-semibold md:align-middle md:leading-10"
< / FormGroup >
>
< / FormElement >
{ { $t ( 'username' ) } }
< FormElement @submit.prevent ="updatePassword" >
< / Label >
< FormGroup >
< input
< FormHeading > { { $t ( 'me.sectionPassword' ) } } < / FormHeading >
id = "username"
< FormPasswordField
v - model . trim = "username"
id = "current-password"
type = "text"
v - model = "currentPassword"
class = "rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
autocomplete = "current-password"
/ >
: label = "$t('currentPassword')"
< Label for = "name" class = "font-semibold md:align-middle md:leading-10" >
/ >
{ { $t ( 'name' ) } }
< FormPasswordField
< / Label >
id = "new-password"
< input
v - model = "newPassword"
id = "name"
autocomplete = "new-password"
v - model . trim = "name"
: label = "$t('setup.newPassword')"
type = "text"
/ >
class = "rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
< FormPasswordField
/ >
id = "confirm-password"
< Label
v - model = "confirmPassword"
for = "email"
autocomplete = "new-password"
class = "font-semibold md:align-middle md:leading-10"
: label = "$t('confirmPassword')"
>
/ >
{ { $t ( 'email' ) } }
< FormActionField type = "submit" :label ="$t('updatePassword')" / >
< / Label >
< / FormGroup >
< input
< / FormElement >
id = "email"
v - model . trim = "email"
type = "email"
class = "rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
/ >
< div class = "col-span-full" >
< BaseButton @click ="submit" > {{ $ t ( ' save ' ) }} < / BaseButton >
< / div >
< / section >
< section class = "grid grid-cols-1 gap-4 md:grid-cols-2" >
< h4 class = "col-span-full py-6 text-2xl" >
{ { $t ( 'me.sectionPassword' ) } }
< / h4 >
< Label
for = "current-password"
class = "font-semibold md:align-middle md:leading-10"
>
{ { $t ( 'currentPassword' ) } }
< / Label >
< input
id = "current-password"
v - model . trim = "currentPassword"
type = "password"
autocomplete = "current-password"
class = "rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
/ >
< Label
for = "new-password"
class = "font-semibold md:align-middle md:leading-10"
>
{ { $t ( 'setup.newPassword' ) } }
< / Label >
< input
id = "new-password"
v - model . trim = "newPassword"
type = "password"
autocomplete = "new-password"
class = "rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
/ >
< Label
for = "confirm-password"
class = "font-semibold md:align-middle md:leading-10"
>
{ { $t ( 'confirmPassword' ) } }
< / Label >
< input
id = "confirm-password"
v - model . trim = "confirmPassword"
type = "password"
autocomplete = "new-password"
class = "rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
/ >
< div class = "col-span-full" >
< BaseButton @click ="updatePassword" > {{
$t ( 'updatePassword' )
} } < / BaseButton >
< / div >
< / section >
< / PanelBody >
< / PanelBody >
< / Panel >
< / Panel >
< / main >
< / main >
< / template >
< / template >
< script setup lang = "ts" >
< script setup lang = "ts" >
import { FetchError } from 'ofetch' ;
const authStore = useAuthStore ( ) ;
const authStore = useAuthStore ( ) ;
authStore . update ( ) ;
authStore . update ( ) ;
const toast = useToast ( ) ;
const username = ref ( authStore . userData ? . username ) ;
const name = ref ( authStore . userData ? . name ) ;
const name = ref ( authStore . userData ? . name ) ;
const email = ref ( authStore . userData ? . email ) ;
/ / T O D O : h a n d l e u p d a t e p a s s w o r d
const rawEmail = ref ( authStore . userData ? . email ) ;
const email = computed ( {
get : ( ) => rawEmail . value ? ? undefined ,
set : ( value ) => {
const temp = value ? . trim ( ) ? ? null ;
if ( temp === '' ) {
rawEmail . value = null ;
return ;
}
rawEmail . value = temp ;
return ;
} ,
} ) ;
const currentPassword = ref ( authStore . userData ? . email ) ;
async function submit ( ) {
const newPassword = ref ( authStore . userData ? . email ) ;
try {
const confirmPassword = ref ( authStore . userData ? . email ) ;
const res = await $fetch ( ` /api/me ` , {
method : 'post' ,
body : {
name : name . value ,
email : rawEmail . value ,
} ,
} ) ;
toast . showToast ( {
type : 'success' ,
title : 'Success' ,
message : 'Saved' ,
} ) ;
if ( ! res . success ) {
throw new Error ( 'Failed to update general' ) ;
}
await refreshNuxtData ( ) ;
} catch ( e ) {
if ( e instanceof FetchError ) {
toast . showToast ( {
type : 'error' ,
title : 'Error' ,
message : e . data . message ,
} ) ;
}
}
}
function submit ( ) { }
/ / T O D O : h a n d l e u p d a t e p a s s w o r d
const currentPassword = ref ( '' ) ;
const newPassword = ref ( '' ) ;
const confirmPassword = ref ( '' ) ;
function updatePassword ( ) { }
async function updatePassword ( ) {
try {
const res = await $fetch ( ` /api/me/password ` , {
method : 'post' ,
body : {
currentPassword : currentPassword . value ,
newPassword : newPassword . value ,
confirmPassword : confirmPassword . value ,
} ,
} ) ;
toast . showToast ( {
type : 'success' ,
title : 'Success' ,
message : 'Saved' ,
} ) ;
if ( ! res . success ) {
throw new Error ( 'Failed to update password' ) ;
}
await refreshNuxtData ( ) ;
} catch ( e ) {
if ( e instanceof FetchError ) {
toast . showToast ( {
type : 'error' ,
title : 'Error' ,
message : e . data . message ,
} ) ;
}
}
}
< / script >
< / script >