1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<template>
<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>
<b-field
label="Username"
message="Nothing to do here"
horizontal>
<b-input
class="hostess-input"
:value="user.username"
expanded
disabled />
</b-field>
<b-field
label="Current password"
message="If you want to change your password input the current one here"
horizontal>
<b-input
v-model="password"
class="hostess-input"
type="password"
expanded />
</b-field>
<b-field
label="New password"
message="Your new password"
horizontal>
<b-input
v-model="newPassword"
class="hostess-input"
type="password"
expanded />
</b-field>
<b-field
label="New password again"
message="Your new password once again"
horizontal>
<b-input
v-model="reNewPassword"
class="hostess-input"
type="password"
expanded />
</b-field>
<div class="mb2 mt2 text-center">
<b-button
type="is-hostess"
@click="changePassword">
Change password
</b-button>
</div>
<b-field
label="API key"
message="This API key lets you use the service from other apps"
horizontal>
<b-field expanded>
<b-input
class="hostess-input"
:value="apiKey"
expanded
disabled />
<p class="control">
<b-button
type="is-hostess"
@click="copyKey">
Copy
</b-button>
</p>
</b-field>
</b-field>
<div class="mb2 mt2 text-center">
<b-button
type="is-hostess"
@click="promptNewAPIKey">
Request new API key
</b-button>
</div>
</div>
</div>
</div>
</section>
</template>
<script>
import { mapState, mapActions, mapGetters } from 'vuex';
import Sidebar from '~/components/sidebar/Sidebar.vue';
export default {
components: {
Sidebar
},
middleware: ['auth'],
data() {
return {
password: '',
newPassword: '',
reNewPassword: ''
};
},
computed: {
...mapGetters({ apiKey: 'auth/getApiKey' }),
...mapState({
user: state => state.auth.user
})
},
async asyncData({ app }) {
await app.store.dispatch('auth/fetchCurrentUser');
},
methods: {
...mapActions({
getUserSetttings: 'auth/fetchCurrentUser'
}),
async changePassword() {
const { password, newPassword, reNewPassword } = this;
if (!password || !newPassword || !reNewPassword) {
this.$store.dispatch('alert/set', {
text: 'One or more fields are missing',
error: true
});
return;
}
if (newPassword !== reNewPassword) {
this.$store.dispatch('alert/set', {
text: 'Passwords don\'t match',
error: true
});
return;
}
const response = await this.$store.dispatch('auth/changePassword', {
password,
newPassword
});
if (response) {
this.$buefy.toast.open(response.message);
}
},
promptNewAPIKey() {
this.$buefy.dialog.confirm({
type: 'is-danger',
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.',
onConfirm: () => this.requestNewAPIKey()
});
},
copyKey() {
this.$clipboard(this.apiKey);
this.$notifier.success('API key copied to clipboard');
},
async requestNewAPIKey() {
const response = await this.$store.dispatch('auth/requestAPIKey');
this.$buefy.toast.open(response.message);
}
},
head() {
return {
title: 'Account'
};
}
};
</script>
|