2019-02-28 15:26:28 +01:00
< style lang = "scss" scoped >
@ import '~/assets/styles/_colors.scss' ;
section { background - color : $backgroundLight1 ! important ; }
section . hero div . hero - body {
align - items : baseline ;
}
div . search - container {
display : flex ;
justify - content : center ;
}
< / style >
< style lang = "scss" >
@ import '~/assets/styles/_colors.scss' ;
< / style >
< template >
< section class = "hero is-fullheight" >
< div class = "hero-body" >
< div class = "container" >
< div class = "columns" >
< div class = "column is-narrow" >
< Sidebar / >
< / div >
< div class = "column" >
< h2 class = "subtitle" > Account settings < / h2 >
< hr >
< b -field label = "Username"
message = "Nothing to do here"
horizontal >
< b -input v -model = " user.username "
expanded
disabled / >
< / b - f i e l d >
< 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 >
< 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 >
< 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 >
< div class = "mb2 mt2 text-center" >
< button class = "button is-primary"
@ click = "changePassword" > Change password < / button >
< / div >
< b -field label = "Api key"
2019-03-02 14:16:35 +01:00
message = "This API key lets you use the service from other apps"
2019-02-28 15:26:28 +01:00
horizontal >
< b -input v -model = " user.apiKey "
2019-03-28 16:35:58 +01:00
expanded
disabled / >
2019-02-28 15:26:28 +01:00
< / b - f i e l d >
< div class = "mb2 mt2 text-center" >
< button class = "button is-primary"
@ click = "promptNewAPIKey" > Request new API key < / button >
< / div >
< / 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 : { }
} ;
} ,
computed : {
config ( ) {
return this . $store . state . config ;
}
} ,
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
} ) ;
this . $toast . open ( response . message ) ;
2019-02-28 15:26:28 +01:00
} ,
promptNewAPIKey ( ) {
this . $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 ( ) ;
this . $toast . open ( response . message ) ;
2019-02-28 15:26:28 +01:00
}
}
} ;
< / script >