2019-02-28 15:26:28 +01:00
< template >
2020-06-29 19:02:47 +02:00
< section class = "section is-fullheight dashboard" >
< div class = "container" >
< div class = "columns" >
< div class = "column is-narrow" >
< Sidebar / >
< / div >
< div class = "column" >
< h2 class = "subtitle" > Account settings < / h2 >
< hr >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< b -field label = "Username"
message = "Nothing to do here"
horizontal >
< b -input v -model = " user.username "
expanded
disabled / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< b -field label = "Current password"
message = "If you want to change your password input the current one here"
horizontal >
< b -input v -model = " user.password "
type = "password"
expanded / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< b -field label = "New password"
message = "Your new password"
horizontal >
< b -input v -model = " user.newPassword "
type = "password"
expanded / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< b -field label = "New password again"
message = "Your new password once again"
horizontal >
< b -input v -model = " user.reNewPassword "
type = "password"
expanded / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< div class = "mb2 mt2 text-center" >
< button class = "button is-primary"
@ click = "changePassword" > Change password < / button >
< / div >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< b -field label = "Api key"
message = "This API key lets you use the service from other apps"
horizontal >
< b -input v -model = " user.apiKey "
expanded
disabled / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-06-29 19:02:47 +02:00
< div class = "mb2 mt2 text-center" >
< button class = "button is-primary"
@ click = "promptNewAPIKey" > Request new API key < / button >
2019-02-28 15:26:28 +01:00
< / div >
< / div >
< / div >
< / div >
< / section >
< / template >
< script >
import Sidebar from '~/components/sidebar/Sidebar.vue' ;
export default {
components : {
Sidebar
} ,
2019-03-28 16:35:58 +01:00
middleware : 'auth' ,
2019-02-28 15:26:28 +01:00
data ( ) {
return {
user : { }
} ;
} ,
metaInfo ( ) {
return { title : 'Account' } ;
} ,
mounted ( ) {
this . getUserSetttings ( ) ;
} ,
methods : {
async getUserSetttings ( ) {
2019-04-24 10:36:28 +02:00
const response = await this . $axios . $get ( ` users/me ` ) ;
this . user = response . user ;
2019-02-28 15:26:28 +01:00
} ,
async changePassword ( ) {
2019-04-24 10:36:28 +02:00
if ( ! this . user . password || ! this . user . newPassword || ! this . user . reNewPassword ) {
this . $store . dispatch ( 'alert' , {
text : 'One or more fields are missing' ,
error : true
} ) ;
return ;
}
if ( this . user . newPassword !== this . user . reNewPassword ) {
this . $store . dispatch ( 'alert' , {
text : 'Passwords don\'t match' ,
error : true
} ) ;
return ;
2019-02-28 15:26:28 +01:00
}
2019-04-24 10:36:28 +02:00
const response = await this . $axios . $post ( ` user/password/change ` ,
{
password : this . user . password ,
newPassword : this . user . newPassword
} ) ;
2019-10-12 08:47:25 +02:00
this . $buefy . toast . open ( response . message ) ;
2019-02-28 15:26:28 +01:00
} ,
promptNewAPIKey ( ) {
2019-10-12 08:47:25 +02:00
this . $buefy . dialog . confirm ( {
2019-03-19 08:58:36 +01:00
type : 'is-danger' ,
2019-03-21 17:47:14 +01:00
message : 'Are you sure you want to regenerate your API key? Previously generated API keys will stop working. Make sure to write the new key down as this is the only time it will be displayed to you.' ,
2019-02-28 15:26:28 +01:00
onConfirm : ( ) => this . requestNewAPIKey ( )
} ) ;
} ,
async requestNewAPIKey ( ) {
2019-04-24 10:36:28 +02:00
const response = await this . $axios . $post ( ` user/apikey/change ` ) ;
this . user . apiKey = response . apiKey ;
this . $forceUpdate ( ) ;
2019-10-12 08:47:25 +02:00
this . $buefy . toast . open ( response . message ) ;
2019-02-28 15:26:28 +01:00
}
}
} ;
< / script >