confirm password when 2fa setup refactored

This commit is contained in:
Čarodej
2022-01-21 09:43:11 +01:00
parent 03e4f98ad6
commit c2667ab481
5 changed files with 204 additions and 221 deletions

View File

@@ -71,8 +71,8 @@
"/chunks/profile~chunks/settings-password.js": "/chunks/profile~chunks/settings-password.js?id=a81388efd770d51f8a9c",
"/chunks/purchase-code.js": "/chunks/purchase-code.js?id=d9af0efad2af2679954b",
"/chunks/recent-uploads.js": "/chunks/recent-uploads.js?id=8577d4c771602671b38a",
"/chunks/settings.js": "/chunks/settings.js?id=4e5b93f9cee2abaa60ac",
"/chunks/settings-password.js": "/chunks/settings-password.js?id=96f0a4f57ef24172c522",
"/chunks/settings.js": "/chunks/settings.js?id=9900b7eb6fe245a852c5",
"/chunks/settings-password.js": "/chunks/settings-password.js?id=cbf4584f8fefdeb7b20f",
"/chunks/settings-storage.js": "/chunks/settings-storage.js?id=84f35e2124d825cc5039",
"/chunks/settings~chunks/settings-password.js": "/chunks/settings~chunks/settings-password.js?id=aafc9cd6aa47b01bc25a",
"/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=651d5accf401908724c5",
@@ -798,5 +798,36 @@
"/chunks/settings.924d3949f14a2b755600.hot-update.js": "/chunks/settings.924d3949f14a2b755600.hot-update.js",
"/chunks/settings-password.c61f80f724c565d44122.hot-update.js": "/chunks/settings-password.c61f80f724c565d44122.hot-update.js",
"/chunks/settings-password.e3947848fdbf30a885c7.hot-update.js": "/chunks/settings-password.e3947848fdbf30a885c7.hot-update.js",
"/chunks/settings-password.425eae13104458d4e284.hot-update.js": "/chunks/settings-password.425eae13104458d4e284.hot-update.js"
"/chunks/settings-password.425eae13104458d4e284.hot-update.js": "/chunks/settings-password.425eae13104458d4e284.hot-update.js",
"/chunks/settings-password.7e15304975cceb0e1328.hot-update.js": "/chunks/settings-password.7e15304975cceb0e1328.hot-update.js",
"/chunks/settings-password.c7aa2e12324dd5e00cfc.hot-update.js": "/chunks/settings-password.c7aa2e12324dd5e00cfc.hot-update.js",
"/chunks/settings.8790e5d07ea9f481a83c.hot-update.js": "/chunks/settings.8790e5d07ea9f481a83c.hot-update.js",
"/chunks/settings.91cb29bc5f14006d200a.hot-update.js": "/chunks/settings.91cb29bc5f14006d200a.hot-update.js",
"/chunks/settings.05185ec63f95385ad8bf.hot-update.js": "/chunks/settings.05185ec63f95385ad8bf.hot-update.js",
"/chunks/settings-password.ef04318a0d1dfe71bc41.hot-update.js": "/chunks/settings-password.ef04318a0d1dfe71bc41.hot-update.js",
"/chunks/settings.1b6d808c8a31988833fe.hot-update.js": "/chunks/settings.1b6d808c8a31988833fe.hot-update.js",
"/chunks/settings.bfebb5eef3b00b5d14d0.hot-update.js": "/chunks/settings.bfebb5eef3b00b5d14d0.hot-update.js",
"/chunks/settings.560520831b359f94e878.hot-update.js": "/chunks/settings.560520831b359f94e878.hot-update.js",
"/chunks/settings.90281abcff546be6e6e6.hot-update.js": "/chunks/settings.90281abcff546be6e6e6.hot-update.js",
"/chunks/settings.703c0dae84a0e532b7c5.hot-update.js": "/chunks/settings.703c0dae84a0e532b7c5.hot-update.js",
"/chunks/settings.6a746de79e910dcd7a0a.hot-update.js": "/chunks/settings.6a746de79e910dcd7a0a.hot-update.js",
"/chunks/settings.23fc0a516889bf4bd4bf.hot-update.js": "/chunks/settings.23fc0a516889bf4bd4bf.hot-update.js",
"/chunks/settings.8980ed8fe25b6e8be24d.hot-update.js": "/chunks/settings.8980ed8fe25b6e8be24d.hot-update.js",
"/chunks/settings.7a26fc2ebc3426a5a525.hot-update.js": "/chunks/settings.7a26fc2ebc3426a5a525.hot-update.js",
"/chunks/settings.41ef7dee3fd39455265b.hot-update.js": "/chunks/settings.41ef7dee3fd39455265b.hot-update.js",
"/chunks/settings.e3d870c02e1796676d68.hot-update.js": "/chunks/settings.e3d870c02e1796676d68.hot-update.js",
"/chunks/settings.bc6564f200c8cca630ac.hot-update.js": "/chunks/settings.bc6564f200c8cca630ac.hot-update.js",
"/chunks/settings.150e77c2529637439e07.hot-update.js": "/chunks/settings.150e77c2529637439e07.hot-update.js",
"/chunks/settings.e9be927c26ec07b6b668.hot-update.js": "/chunks/settings.e9be927c26ec07b6b668.hot-update.js",
"/chunks/settings.695b0b5748bd36051746.hot-update.js": "/chunks/settings.695b0b5748bd36051746.hot-update.js",
"/chunks/settings.64292997f44763212c1c.hot-update.js": "/chunks/settings.64292997f44763212c1c.hot-update.js",
"/chunks/settings-password.78a4407d5d136c8cfb53.hot-update.js": "/chunks/settings-password.78a4407d5d136c8cfb53.hot-update.js",
"/chunks/settings-password.d00a52eb7df67c6db0fb.hot-update.js": "/chunks/settings-password.d00a52eb7df67c6db0fb.hot-update.js",
"/chunks/settings-password.92f17ff82d1c728f4aa5.hot-update.js": "/chunks/settings-password.92f17ff82d1c728f4aa5.hot-update.js",
"/chunks/settings-password.949c126c8cad70828575.hot-update.js": "/chunks/settings-password.949c126c8cad70828575.hot-update.js",
"/chunks/settings.0a54c78cc9755b8ec6bd.hot-update.js": "/chunks/settings.0a54c78cc9755b8ec6bd.hot-update.js",
"/chunks/settings.4da40f5fec3b7d81d945.hot-update.js": "/chunks/settings.4da40f5fec3b7d81d945.hot-update.js",
"/chunks/settings.b6ad682da66d3b2069ed.hot-update.js": "/chunks/settings.b6ad682da66d3b2069ed.hot-update.js",
"/chunks/settings.3ecffd8e41b9e910f512.hot-update.js": "/chunks/settings.3ecffd8e41b9e910f512.hot-update.js",
"/chunks/settings-password.07cfa125159d6148dbaa.hot-update.js": "/chunks/settings-password.07cfa125159d6148dbaa.hot-update.js"
}

View File

@@ -0,0 +1,128 @@
<template>
<PopupWrapper name="two-factor-qr-setup">
<PopupHeader :title="$t('popup_2fa.title')" icon="edit" />
<PopupContent>
<div v-if="qrCode" class="flex justify-center">
<div v-html="qrCode" class="my-5"></div>
</div>
<InfoBox style="margin-bottom: 0">
<p v-html="$t('popup_2fa.help')"></p>
</InfoBox>
</PopupContent>
<PopupActions>
<ButtonBase
class="w-full"
@click.native="closeQrCodePopup"
:button-style="closeQrButtonStyle"
>
{{ closeQrButtonText }}
</ButtonBase>
</PopupActions>
</PopupWrapper>
</template>
<script>
import AppInputText from "../Admin/AppInputText";
import {ValidationProvider, ValidationObserver} from 'vee-validate/dist/vee-validate.full'
import PopupWrapper from '/resources/js/components/Others/Popup/PopupWrapper'
import PopupActions from '/resources/js/components/Others/Popup/PopupActions'
import PopupContent from '/resources/js/components/Others/Popup/PopupContent'
import PopupHeader from '/resources/js/components/Others/Popup/PopupHeader'
import ButtonBase from '/resources/js/components/FilesView/ButtonBase'
import InfoBox from '/resources/js/components/Others/Forms/InfoBox'
import {required} from 'vee-validate/dist/rules'
import {mapGetters} from 'vuex'
import {events} from '/resources/js/bus'
import axios from 'axios'
export default {
name: "TwoFactorQrSetupPopup",
components: {
ValidationProvider,
ValidationObserver,
AppInputText,
PopupWrapper,
PopupActions,
PopupContent,
PopupHeader,
ButtonBase,
required,
InfoBox,
},
computed: {
...mapGetters([
'user'
]),
closeQrButtonText() {
return this.isConfirmedClose
? this.$t('popup_2fa.disappear_qr')
: this.$t('shared_form.button_done')
},
closeQrButtonStyle() {
return this.isConfirmedClose
? 'danger'
: 'theme'
},
},
data() {
return {
isLoading: false,
qrCode: '',
isConfirmedClose: false,
}
},
methods: {
enable() {
axios
.post('/user/two-factor-authentication')
.then(() => {
this.$store.commit('CHANGE_TWO_FACTOR_AUTHENTICATION_STATE', true)
this.getQrCode()
})
.catch(() => {
this.$isSomethingWrong()
})
},
getQrCode() {
axios
.get('/user/two-factor-qr-code')
.then(response => {
this.qrCode = response.data.svg
})
.catch(() => {
this.$isSomethingWrong()
})
},
closeQrCodePopup() {
if (!this.isConfirmedClose) {
this.isConfirmedClose = true
} else {
events.$emit('toaster', {
type: 'success',
message: this.$t('popup_2fa.toaster_enabled'),
})
this.qrCode = undefined
this.isConfirmedClose = false
this.$closePopup()
}
}
},
created() {
// Show popup
events.$on('popup:open', args => {
if (args.name !== 'two-factor-qr-setup') return
this.enable()
})
}
}
</script>

View File

@@ -1,211 +0,0 @@
<template>
<PopupWrapper name="two-factor-authentication-confirm">
<PopupHeader :title="$t('popup_2fa.title')" icon="edit" />
<PopupContent>
<ValidationObserver @submit.prevent="confirmPassword" v-if="! qrCode" ref="passwordForm" v-slot="{ invalid }" tag="form">
<ValidationProvider tag="div" mode="passive" name="Password" rules="required" v-slot="{ errors }">
<AppInputText :title="$t('popup_2fa.input_label')" :error="errors[0]" :is-last="true">
<input v-model="password" :class="{'border-red': errors[0]}" type="password" ref="input" class="focus-border-theme input-dark" :placeholder="$t('page_sign_in.placeholder_password')">
</AppInputText>
</ValidationProvider>
</ValidationObserver>
<div v-if="qrCode" class="qr-code-wrapper">
<div class="qr-code">
<div v-html="qrCode"></div>
</div>
<InfoBox style="margin-bottom: 0">
<p v-html="$t('popup_2fa.help')"></p>
</InfoBox>
</div>
</PopupContent>
<PopupActions v-if="! qrCode">
<ButtonBase
class="w-full"
@click.native="$closePopup()"
button-style="secondary"
>
{{ $t('global.cancel') }}
</ButtonBase>
<ButtonBase
class="w-full"
@click.native="confirmPassword"
button-style="theme"
:loading="isLoading"
:disabled="isLoading"
>
{{ $t('popup_2fa.confirm_button') }}
</ButtonBase>
</PopupActions>
<PopupActions v-if="qrCode">
<ButtonBase
class="w-full"
@click.native="closeQrCodePopup"
:button-style="closeQrButtonStyle"
>
{{ closeQrButtonText }}
</ButtonBase>
</PopupActions>
</PopupWrapper>
</template>
<script>
import AppInputText from "../Admin/AppInputText";
import {ValidationProvider, ValidationObserver} from 'vee-validate/dist/vee-validate.full'
import PopupWrapper from '/resources/js/components/Others/Popup/PopupWrapper'
import PopupActions from '/resources/js/components/Others/Popup/PopupActions'
import PopupContent from '/resources/js/components/Others/Popup/PopupContent'
import PopupHeader from '/resources/js/components/Others/Popup/PopupHeader'
import ButtonBase from '/resources/js/components/FilesView/ButtonBase'
import InfoBox from '/resources/js/components/Others/Forms/InfoBox'
import {required} from 'vee-validate/dist/rules'
import {mapGetters} from 'vuex'
import {events} from '/resources/js/bus'
import axios from 'axios'
export default {
name: "TwoFactorSetupPopup",
components: {
ValidationProvider,
ValidationObserver,
AppInputText,
PopupWrapper,
PopupActions,
PopupContent,
PopupHeader,
ButtonBase,
required,
InfoBox,
},
computed: {
...mapGetters(['user']),
closeQrButtonText() {
return this.isConfirmedClose
? this.$t('popup_2fa.disappear_qr')
: this.$t('shared_form.button_done')
},
closeQrButtonStyle() {
return this.isConfirmedClose
? 'danger'
: 'theme'
},
},
data() {
return {
isLoading: false,
password: '',
qrCode: '',
isConfirmedClose: false,
}
},
methods: {
confirmPassword() {
this.isLoading = true
axios
.post('/user/confirm-password', {
password: this.password
})
.then(() => {
if (!this.user.data.attributes.two_factor_authentication) {
this.enable()
} else {
this.disable()
}
})
.catch(error => {
if (error.response.status == 422) {
this.$refs.passwordForm.setErrors({
'Password': this.$t('validation_errors.incorrect_password')
});
}
})
.finally(() => {
this.isLoading = false
this.password = undefined
})
},
enable() {
axios
.post('/user/two-factor-authentication')
.then(() => {
this.$store.commit('CHANGE_TWO_FACTOR_AUTHENTICATION_STATE', true)
this.getQrCode()
})
.catch(() => {
this.$isSomethingWrong()
})
},
disable() {
axios
.delete('/user/two-factor-authentication')
.then(() => {
this.$store.commit('CHANGE_TWO_FACTOR_AUTHENTICATION_STATE', false)
})
.catch(() => {
this.$isSomethingWrong()
})
.finally(() => {
events.$emit('toaster', {
type: 'success',
message: this.$t('popup_2fa.toaster_disabled'),
})
this.$closePopup()
})
},
getQrCode() {
axios
.get('/user/two-factor-qr-code')
.then(response => {
this.qrCode = response.data.svg
})
.catch(() => {
this.$isSomethingWrong()
})
},
closeQrCodePopup() {
if (!this.isConfirmedClose) {
this.isConfirmedClose = true
} else {
events.$emit('toaster', {
type: 'success',
message: this.$t('popup_2fa.toaster_enabled'),
})
this.qrCode = undefined
this.isConfirmedClose = false
this.$closePopup()
}
}
}
}
</script>
<style lang="scss" scoped>
@import "resources/sass/vuefilemanager/_inapp-forms.scss";
@import '/resources/sass/vuefilemanager/_forms';
.qr-code-wrapper {
.qr-code {
display: flex;
justify-content: center;
margin: 20px 0;
}
}
</style>

View File

@@ -10,7 +10,7 @@
<!--2FA popups-->
<TwoFactorRecoveryCodesPopup />
<TwoFactorSetupPopup />
<TwoFactorQrSetupPopup />
<!--Access Token Popup-->
<CreatePersonaTokenPopup />
@@ -69,7 +69,7 @@
import Spotlight from '/resources/js/components/Spotlight/Spotlight'
import TwoFactorRecoveryCodesPopup from '/resources/js/components/Others/TwoFactorRecoveryCodesPopup'
import CreatePersonaTokenPopup from '/resources/js/components/Others/CreatePersonaTokenPopup'
import TwoFactorSetupPopup from '/resources/js/components/Others/TwoFactorSetupPopup'
import TwoFactorQrSetupPopup from '/resources/js/components/Others/TwoFactorQrSetupPopup'
import UserImageInput from '/resources/js/components/Others/UserImageInput'
import SidebarNavigation from "../components/Sidebar/SidebarNavigation"
import ColorLabel from '/resources/js/components/Others/ColorLabel'
@@ -92,7 +92,7 @@
Spotlight,
TwoFactorRecoveryCodesPopup,
CreatePersonaTokenPopup,
TwoFactorSetupPopup,
TwoFactorQrSetupPopup,
SidebarNavigation,
UserImageInput,
ColorLabel,

View File

@@ -7,7 +7,7 @@
{{ $t('2fa.settings.title') }}
</FormLabel>
<AppInputSwitch :title="$t('popup_2fa.switch_title')" :description="$t('popup_2fa.switch_info')" :is-last="! user.data.attributes.two_factor_authentication">
<SwitchInput @click.native.prevent.stop="open2faPopup" class="switch" :state="user.data.attributes.two_factor_authentication" />
<SwitchInput v-model="user.data.attributes.two_factor_authentication" class="switch" :state="user.data.attributes.two_factor_authentication" />
</AppInputSwitch>
<AppInputSwitch v-if="user && user.data.attributes.two_factor_authentication" :title="$t('popup_2fa.codes_title')" :description="$t('popup_2fa.codes_info')" :is-last="true">
<ButtonBase class="w-full" button-style="secondary" @click.native="showRecoveryCodes">
@@ -112,6 +112,15 @@
'user',
])
},
watch: {
'user.data.attributes.two_factor_authentication': function (val) {
if (val) {
this.open2faPopup()
} else {
this.disable()
}
}
},
data() {
return {
passwordForm: {
@@ -170,6 +179,22 @@
}
})
},
disable() {
axios
.delete('/user/two-factor-authentication')
.then(() => {
this.$store.commit('CHANGE_TWO_FACTOR_AUTHENTICATION_STATE', false)
})
.catch(() => {
this.$isSomethingWrong()
})
.finally(() => {
events.$emit('toaster', {
type: 'success',
message: this.$t('popup_2fa.toaster_disabled'),
})
})
},
getPersonalAccessTokens() {
axios.get('/api/user/tokens')
.then(response => {
@@ -185,6 +210,14 @@
}
})
},
open2faPopup() {
events.$emit('popup:open', {
name: 'confirm-password',
options: {
action: 'two-factor-qr-setup',
}
})
},
confirmDeleteToken(token) {
events.$emit('confirm:open', {
title: this.$t('popup_delete_personal_token.title'),
@@ -195,9 +228,6 @@
}
})
},
open2faPopup() {
events.$emit('popup:open', {name: 'two-factor-authentication-confirm'})
},
openCreateTokenPopup() {
events.$emit('popup:open', {name: 'create-personal-token'})
},
@@ -234,6 +264,11 @@
if (args.options.action === 'get-recovery-codes') {
events.$emit('popup:open', {name: 'two-factor-recovery-codes'})
}
// Get 2fa qr code
if (args.options.action === 'two-factor-qr-setup') {
events.$emit('popup:open', {name: 'two-factor-qr-setup'})
}
})
events.$on('reload-personal-access-tokens', () => this.getPersonalAccessTokens())