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" >
2020-07-07 01:02:59 +02:00
< h2 class = "subtitle" >
Account settings
< / h2 >
2020-06-29 19:02:47 +02:00
< hr >
2019-02-28 15:26:28 +01:00
2020-07-07 01:02:59 +02:00
< b -field
label = "Username"
2020-06-29 19:02:47 +02:00
message = "Nothing to do here"
horizontal >
2020-07-07 01:02:59 +02:00
< b -input
2020-12-25 12:45:22 +01:00
class = "chibisafe-input"
2020-07-07 01:02:59 +02:00
: value = "user.username"
2020-06-29 19:02:47 +02:00
expanded
disabled / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-07-07 01:02:59 +02:00
< b -field
label = "Current password"
2020-06-29 19:02:47 +02:00
message = "If you want to change your password input the current one here"
horizontal >
2020-07-07 01:02:59 +02:00
< b -input
v - model = "password"
2020-12-25 12:45:22 +01:00
class = "chibisafe-input"
2020-06-29 19:02:47 +02:00
type = "password"
expanded / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-07-07 01:02:59 +02:00
< b -field
label = "New password"
2020-06-29 19:02:47 +02:00
message = "Your new password"
horizontal >
2020-07-07 01:02:59 +02:00
< b -input
v - model = "newPassword"
2020-12-25 12:45:22 +01:00
class = "chibisafe-input"
2020-06-29 19:02:47 +02:00
type = "password"
expanded / >
< / b - f i e l d >
2019-02-28 15:26:28 +01:00
2020-07-07 01:02:59 +02:00
< b -field
label = "New password again"
2020-06-29 19:02:47 +02:00
message = "Your new password once again"
horizontal >
2020-07-07 01:02:59 +02:00
< b -input
v - model = "reNewPassword"
2020-12-25 12:45:22 +01:00
class = "chibisafe-input"
2020-06-29 19:02:47 +02:00
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" >
2020-07-09 01:24:40 +02:00
< b -button
2020-12-25 12:45:22 +01:00
type = "is-chibisafe"
2020-07-07 01:02:59 +02:00
@ click = "changePassword" >
Change password
2020-07-09 01:24:40 +02:00
< / b - b u t t o n >
2020-06-29 19:02:47 +02:00
< / div >
2019-02-28 15:26:28 +01:00
2020-07-07 01:02:59 +02:00
< b -field
label = "API key"
2020-06-29 19:02:47 +02:00
message = "This API key lets you use the service from other apps"
horizontal >
2020-07-02 22:42:02 +02:00
< b -field expanded >
2020-07-07 01:02:59 +02:00
< b -input
2020-12-25 12:45:22 +01:00
class = "chibisafe-input"
2020-07-07 01:02:59 +02:00
: value = "apiKey"
2020-07-02 22:42:02 +02:00
expanded
disabled / >
< p class = "control" >
2020-07-09 01:24:40 +02:00
< b -button
2020-12-25 12:45:22 +01:00
type = "is-chibisafe"
2020-07-09 01:24:40 +02:00
@ click = "copyKey" >
2020-07-07 01:02:59 +02:00
Copy
2020-07-09 01:24:40 +02:00
< / b - b u t t o n >
2020-07-02 22:42:02 +02:00
< / p >
< / b - f i e l d >
2020-06-29 19:02:47 +02:00
< / 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" >
2020-07-09 01:24:40 +02:00
< b -button
2020-12-25 12:45:22 +01:00
type = "is-chibisafe"
2020-07-07 01:02:59 +02:00
@ click = "promptNewAPIKey" >
Request new API key
2020-07-09 01:24:40 +02:00
< / b - b u t t o n >
2019-02-28 15:26:28 +01:00
< / div >
< / div >
< / div >
< / div >
< / section >
< / template >
< script >
2020-07-02 22:42:02 +02:00
import { mapState , mapActions , mapGetters } from 'vuex' ;
2019-02-28 15:26:28 +01:00
import Sidebar from '~/components/sidebar/Sidebar.vue' ;
export default {
components : {
2020-12-24 09:40:50 +01:00
Sidebar
2019-02-28 15:26:28 +01:00
} ,
2020-07-02 22:42:02 +02:00
middleware : [ 'auth' , ( { store } ) => {
store . dispatch ( 'auth/fetchCurrentUser' ) ;
} ] ,
2019-02-28 15:26:28 +01:00
data ( ) {
return {
2020-07-02 22:42:02 +02:00
password : '' ,
newPassword : '' ,
2020-12-24 09:40:50 +01:00
reNewPassword : ''
2019-02-28 15:26:28 +01:00
} ;
2020-07-07 01:02:59 +02:00
} ,
2020-07-02 22:42:02 +02:00
computed : {
2020-12-24 15:45:16 +01:00
... mapGetters ( { apiKey : 'auth/getApiKey' } ) ,
2020-07-02 22:42:02 +02:00
... mapState ( {
2020-12-24 15:45:16 +01:00
user : state => state . auth . user
2020-12-24 09:40:50 +01:00
} )
2019-02-28 15:26:28 +01:00
} ,
metaInfo ( ) {
return { title : 'Account' } ;
} ,
methods : {
2020-07-02 22:42:02 +02:00
... mapActions ( {
2020-12-24 09:40:50 +01:00
getUserSetttings : 'auth/fetchCurrentUser'
2020-07-02 22:42:02 +02:00
} ) ,
2019-02-28 15:26:28 +01:00
async changePassword ( ) {
2020-07-02 22:42:02 +02:00
const { password , newPassword , reNewPassword } = this ;
if ( ! password || ! newPassword || ! reNewPassword ) {
this . $store . dispatch ( 'alert/set' , {
2019-04-24 10:36:28 +02:00
text : 'One or more fields are missing' ,
2020-12-24 09:40:50 +01:00
error : true
2019-04-24 10:36:28 +02:00
} ) ;
return ;
}
2020-07-02 22:42:02 +02:00
if ( newPassword !== reNewPassword ) {
this . $store . dispatch ( 'alert/set' , {
2019-04-24 10:36:28 +02:00
text : 'Passwords don\'t match' ,
2020-12-24 09:40:50 +01:00
error : true
2019-04-24 10:36:28 +02:00
} ) ;
return ;
2019-02-28 15:26:28 +01:00
}
2019-04-24 10:36:28 +02:00
2020-07-02 22:42:02 +02:00
const response = await this . $store . dispatch ( 'auth/changePassword' , {
password ,
2020-12-24 09:40:50 +01:00
newPassword
2020-07-02 22:42:02 +02:00
} ) ;
if ( response ) {
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.' ,
2020-12-24 09:40:50 +01:00
onConfirm : ( ) => this . requestNewAPIKey ( )
2019-02-28 15:26:28 +01:00
} ) ;
} ,
2020-07-09 01:24:40 +02:00
copyKey ( ) {
this . $clipboard ( this . apiKey ) ;
this . $notifier . success ( 'API key copied to clipboard' ) ;
} ,
2019-02-28 15:26:28 +01:00
async requestNewAPIKey ( ) {
2020-07-07 01:02:59 +02:00
const response = await this . $store . dispatch ( 'auth/requestAPIKey' ) ;
2019-10-12 08:47:25 +02:00
this . $buefy . toast . open ( response . message ) ;
2020-12-24 09:40:50 +01:00
}
}
2019-02-28 15:26:28 +01:00
} ;
< / script >