-
Notifications
You must be signed in to change notification settings - Fork 846
/
Copy pathTwoFactorAuthenticationForm.vue
169 lines (145 loc) · 6.13 KB
/
TwoFactorAuthenticationForm.vue
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
<template>
<jet-action-section>
<template #title>
Two Factor Authentication
</template>
<template #description>
Add additional security to your account using two factor authentication.
</template>
<template #content>
<h3 class="text-lg font-medium text-gray-900" v-if="twoFactorEnabled">
You have enabled two factor authentication.
</h3>
<h3 class="text-lg font-medium text-gray-900" v-else>
You have not enabled two factor authentication.
</h3>
<div class="mt-3 max-w-xl text-sm text-gray-600">
<p>
When two factor authentication is enabled, you will be prompted for a secure, random token during authentication. You may retrieve this token from your phone's Google Authenticator application.
</p>
</div>
<div v-if="twoFactorEnabled">
<div v-if="qrCode">
<div class="mt-4 max-w-xl text-sm text-gray-600">
<p class="font-semibold">
Two factor authentication is now enabled. Scan the following QR code using your phone's authenticator application.
</p>
</div>
<div class="mt-4 dark:p-4 dark:w-56 dark:bg-white" v-html="qrCode">
</div>
</div>
<div v-if="recoveryCodes.length > 0">
<div class="mt-4 max-w-xl text-sm text-gray-600">
<p class="font-semibold">
Store these recovery codes in a secure password manager. They can be used to recover access to your account if your two factor authentication device is lost.
</p>
</div>
<div class="grid gap-1 max-w-xl mt-4 px-4 py-4 font-mono text-sm bg-gray-100 rounded-lg">
<div v-for="code in recoveryCodes" :key="code">
{{ code }}
</div>
</div>
</div>
</div>
<div class="mt-5">
<div v-if="! twoFactorEnabled">
<jet-confirms-password @confirmed="enableTwoFactorAuthentication">
<jet-button type="button" :class="{ 'opacity-25': enabling }" :disabled="enabling">
Enable
</jet-button>
</jet-confirms-password>
</div>
<div v-else>
<jet-confirms-password @confirmed="regenerateRecoveryCodes">
<jet-secondary-button class="mr-3"
v-if="recoveryCodes.length > 0">
Regenerate Recovery Codes
</jet-secondary-button>
</jet-confirms-password>
<jet-confirms-password @confirmed="showRecoveryCodes">
<jet-secondary-button class="mr-3" v-if="recoveryCodes.length == 0">
Show Recovery Codes
</jet-secondary-button>
</jet-confirms-password>
<jet-confirms-password @confirmed="disableTwoFactorAuthentication">
<jet-danger-button
:class="{ 'opacity-25': disabling }"
:disabled="disabling">
Disable
</jet-danger-button>
</jet-confirms-password>
</div>
</div>
</template>
</jet-action-section>
</template>
<script>
import JetActionSection from '@/Jetstream/ActionSection'
import JetButton from '@/Jetstream/Button'
import JetConfirmsPassword from '@/Jetstream/ConfirmsPassword'
import JetDangerButton from '@/Jetstream/DangerButton'
import JetSecondaryButton from '@/Jetstream/SecondaryButton'
export default {
components: {
JetActionSection,
JetButton,
JetConfirmsPassword,
JetDangerButton,
JetSecondaryButton,
},
data() {
return {
enabling: false,
disabling: false,
qrCode: null,
recoveryCodes: [],
}
},
methods: {
enableTwoFactorAuthentication() {
this.enabling = true
this.$inertia.post('/user/two-factor-authentication', {}, {
preserveScroll: true,
}).then(() => {
return Promise.all([
this.showQrCode(),
this.showRecoveryCodes()
])
}).then(() => {
this.enabling = false
})
},
showQrCode() {
return axios.get('/user/two-factor-qr-code')
.then(response => {
this.qrCode = response.data.svg
})
},
showRecoveryCodes() {
return axios.get('/user/two-factor-recovery-codes')
.then(response => {
this.recoveryCodes = response.data
})
},
regenerateRecoveryCodes() {
axios.post('/user/two-factor-recovery-codes')
.then(response => {
this.showRecoveryCodes()
})
},
disableTwoFactorAuthentication() {
this.disabling = true
this.$inertia.delete('/user/two-factor-authentication', {
preserveScroll: true,
}).then(() => {
this.disabling = false
})
},
},
computed: {
twoFactorEnabled() {
return ! this.enabling && this.$page.user.two_factor_enabled
}
}
}
</script>