Finalize two-factor handling on account.
This commit is contained in:
parent
0cc895f2d5
commit
7711b697ad
13 changed files with 299 additions and 137 deletions
|
@ -3,7 +3,7 @@
|
|||
<navigation/>
|
||||
<div class="container animate fadein mt-2 sm:mt-6">
|
||||
<modal :show="modalVisible" v-on:close="modalVisible = false">
|
||||
<TwoFactorAuthentication/>
|
||||
<TwoFactorAuthentication v-on:close="modalVisible = false"/>
|
||||
</modal>
|
||||
<flash container="mt-2 sm:mt-6 mb-2"/>
|
||||
<div class="flex flex-wrap">
|
||||
|
@ -11,7 +11,7 @@
|
|||
<div class="sm:m-4 md:ml-0">
|
||||
<update-email class="mb-4 sm:mb-8"/>
|
||||
<div class="content-box text-center mb-4 sm:mb-0">
|
||||
<button class="btn btn-green btn-sm" type="submit" v-on:click="modalVisible = true">Configure 2-Factor Authentication</button>
|
||||
<button class="btn btn-green btn-sm" type="submit" v-on:click="openModal">Configure 2-Factor Authentication</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -39,5 +39,11 @@
|
|||
modalVisible: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
openModal: function () {
|
||||
this.$data.modalVisible = true;
|
||||
window.events.$emit('two_factor:open');
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -2,26 +2,26 @@
|
|||
<div>
|
||||
<form method="post" v-on:submit.prevent="submitForm">
|
||||
<div class="content-box">
|
||||
<h2 class="mb-6 text-grey-darkest font-medium">Change your password</h2>
|
||||
<h2 class="mb-6 text-grey-darkest font-medium">{{ $t('dashboard.account.password.title') }}</h2>
|
||||
<div class="mt-6">
|
||||
<label for="grid-password-current" class="input-label">Current password</label>
|
||||
<label for="grid-password-current" class="input-label">{{ $t('strings.password') }}</label>
|
||||
<input id="grid-password-current" name="current_password" type="password" class="input" required
|
||||
ref="current"
|
||||
v-model="current"
|
||||
>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<label for="grid-password-new" class="input-label">New password</label>
|
||||
<label for="grid-password-new" class="input-label">{{ $t('strings.new_password') }}</label>
|
||||
<input id="grid-password-new" name="password" type="password" class="input" required
|
||||
:class="{ error: errors.has('password') }"
|
||||
v-model="newPassword"
|
||||
v-validate="'min:8'"
|
||||
>
|
||||
<p class="input-help error" v-show="errors.has('password')">{{ errors.first('password') }}</p>
|
||||
<p class="input-help">Your new password should be at least 8 characters in length.</p>
|
||||
<p class="input-help">{{ $t('dashboard.account.password.requirements') }}</p>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<label for="grid-password-new-confirm" class="input-label">Confirm new password</label>
|
||||
<label for="grid-password-new-confirm" class="input-label">{{ $t('strings.confirm_password') }}</label>
|
||||
<input id="grid-password-new-confirm" name="password_confirmation" type="password" class="input" required
|
||||
:class="{ error: errors.has('password_confirmation') }"
|
||||
v-model="confirmNew"
|
||||
|
@ -31,7 +31,7 @@
|
|||
<p class="input-help error" v-show="errors.has('password_confirmation')">{{ errors.first('password_confirmation') }}</p>
|
||||
</div>
|
||||
<div class="mt-6 text-right">
|
||||
<button class="btn btn-blue btn-sm text-right" type="submit">Save</button>
|
||||
<button class="btn btn-blue btn-sm text-right" type="submit">{{ $t('strings.save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -68,7 +68,7 @@
|
|||
this.$data.newPassword = '';
|
||||
this.$data.confirmNew = '';
|
||||
|
||||
this.success('Your password has been updated.');
|
||||
this.success(this.$t('dashboard.account.password.updated'));
|
||||
})
|
||||
.catch(err => {
|
||||
if (!err.response) {
|
||||
|
|
|
@ -1,11 +1,191 @@
|
|||
<template>
|
||||
<div>
|
||||
Todo: put the 2FA magic here!
|
||||
<div class="h-16 text-center" v-show="spinner">
|
||||
<span class="spinner spinner-xl text-blue"></span>
|
||||
</div>
|
||||
<div v-if="response.enabled" v-show="!spinner">
|
||||
<h2 class="font-medium text-grey-darkest">{{ $t('dashboard.account.two_factor.disable.title') }}</h2>
|
||||
<div class="mt-6">
|
||||
<label class="input-label" for="grid-two-factor-token-disable">{{ $t('dashboard.account.two_factor.disable.field') }}</label>
|
||||
<input id="grid-two-factor-token-disable" type="number" class="input"
|
||||
name="token"
|
||||
v-model="token"
|
||||
ref="token"
|
||||
v-validate="'length:6'"
|
||||
:class="{ error: errors.has('token') }"
|
||||
>
|
||||
<p class="input-help error" v-show="errors.has('token')">{{ errors.first('token') }}</p>
|
||||
</div>
|
||||
<div class="mt-6 w-full text-right">
|
||||
<button class="btn btn-sm btn-secondary mr-4" v-on:click="$emit('close')">
|
||||
Cancel
|
||||
</button>
|
||||
<button class="btn btn-sm btn-red" type="submit"
|
||||
:disabled="submitDisabled"
|
||||
v-on:click.prevent="disableTwoFactor"
|
||||
>{{ $t('strings.disable') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else v-show="!spinner">
|
||||
<h2 class="font-medium text-grey-darkest">{{ $t('dashboard.account.two_factor.setup.title') }}</h2>
|
||||
<div class="flex mt-6">
|
||||
<div class="flex-none w-full sm:w-1/2 text-center">
|
||||
<div>
|
||||
<img :src="response.qr_image" alt="Two-factor qr image" class="w-3/4">
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-grey-darker mb-2">{{ $t('dashboard.account.two_factor.setup.help') }}</p>
|
||||
<p class="text-xs"><code>{{response.secret}}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-none w-full sm:w-1/2">
|
||||
<div>
|
||||
<label class="input-label" for="grid-two-factor-token">{{ $t('dashboard.account.two_factor.setup.field') }}</label>
|
||||
<input id="grid-two-factor-token" type="number" class="input"
|
||||
name="token"
|
||||
v-model="token"
|
||||
ref="token"
|
||||
v-validate="'length:6'"
|
||||
:class="{ error: errors.has('token') }"
|
||||
>
|
||||
<p class="input-help error" v-show="errors.has('token')">{{ errors.first('token') }}</p>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<button class="btn btn-blue btn-jumbo" type="submit"
|
||||
:disabled="submitDisabled"
|
||||
v-on:click.prevent="enableTwoFactor"
|
||||
>{{ $t('strings.enable') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Vue from 'vue';
|
||||
import isObject from 'lodash/isObject';
|
||||
|
||||
export default {
|
||||
name: 'TwoFactorAuthentication'
|
||||
name: 'TwoFactorAuthentication',
|
||||
data: function () {
|
||||
return {
|
||||
spinner: true,
|
||||
token: '',
|
||||
submitDisabled: true,
|
||||
response: {
|
||||
enabled: false,
|
||||
qr_image: '',
|
||||
secret: '',
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Before the component is mounted setup the event listener. This event is fired when a user
|
||||
* presses the 'Configure 2-Factor' button on their account page. Once this happens we fire off
|
||||
* a HTTP request to get their information.
|
||||
*/
|
||||
mounted: function () {
|
||||
window.events.$on('two_factor:open', () => {
|
||||
this.prepareModalContent();
|
||||
});
|
||||
},
|
||||
|
||||
watch: {
|
||||
token: function (value) {
|
||||
this.$data.submitDisabled = value.length !== 6;
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* Determine the correct content to show in the modal.
|
||||
*/
|
||||
prepareModalContent: function () {
|
||||
// Reset the data object when the modal is opened again.
|
||||
Object.assign(this.$data, this.$options.data());
|
||||
|
||||
window.axios.get(this.route('account.two_factor'))
|
||||
.finally(() => {
|
||||
this.clearFlashes();
|
||||
})
|
||||
.then(response => {
|
||||
this.$data.response = response.data;
|
||||
this.$data.spinner = false;
|
||||
Vue.nextTick().then(() => {
|
||||
this.$refs.token.focus();
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
if (!error.response) {
|
||||
this.error(error.message);
|
||||
}
|
||||
|
||||
const response = error.response;
|
||||
if (response.data && isObject(response.data.errors)) {
|
||||
response.data.errors.forEach(e => {
|
||||
this.error(e.detail);
|
||||
});
|
||||
}
|
||||
|
||||
this.$emit('close');
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable two-factor authentication on the account by validating the token provided by the user.
|
||||
* Close the modal once the request completes so that the success or error message can be shown
|
||||
* to the user.
|
||||
*/
|
||||
enableTwoFactor: function () {
|
||||
return this._callInternalApi('account.two_factor.enable', 'enabled');
|
||||
},
|
||||
|
||||
/**
|
||||
* Disables two-factor authentication for the client account and closes the modal.
|
||||
*/
|
||||
disableTwoFactor: function () {
|
||||
return this._callInternalApi('account.two_factor.disable', 'disabled');
|
||||
},
|
||||
|
||||
/**
|
||||
* Call the Panel API endpoint and handle errors.
|
||||
*
|
||||
* @param {String} route
|
||||
* @param {String} langKey
|
||||
* @private
|
||||
*/
|
||||
_callInternalApi: function (route, langKey) {
|
||||
window.axios.post(this.route(route), {
|
||||
token: this.$data.token,
|
||||
})
|
||||
.finally(() => {
|
||||
this.clearFlashes();
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.success(this.$t(`dashboard.account.two_factor.${langKey}`));
|
||||
} else {
|
||||
this.error(this.$t('dashboard.account.two_factor.invalid'));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (!error.response) {
|
||||
this.error(error.message);
|
||||
}
|
||||
|
||||
const response = error.response;
|
||||
if (response.data && isObject(response.data.errors)) {
|
||||
response.data.errors.forEach(e => {
|
||||
this.error(e.detail);
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.$emit('close');
|
||||
})
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<div :class>
|
||||
<form method="post" v-on:submit.prevent="submitForm">
|
||||
<div class="content-box">
|
||||
<h2 class="mb-6 text-grey-darkest font-medium">Update your email</h2>
|
||||
<h2 class="mb-6 text-grey-darkest font-medium">{{ $t('dashboard.account.email.title') }}</h2>
|
||||
<div>
|
||||
<label for="grid-email" class="input-label">Email address</label>
|
||||
<label for="grid-email" class="input-label">{{ $t('strings.email_address') }}</label>
|
||||
<input id="grid-email" name="email" type="email" class="input" required
|
||||
:class="{ error: errors.has('email') }"
|
||||
v-validate
|
||||
|
@ -13,13 +13,13 @@
|
|||
<p class="input-help error" v-show="errors.has('email')">{{ errors.first('email') }}</p>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<label for="grid-password" class="input-label">Password</label>
|
||||
<label for="grid-password" class="input-label">{{ $t('strings.password') }}</label>
|
||||
<input id="grid-password" name="password" type="password" class="input" required
|
||||
v-model="password"
|
||||
>
|
||||
</div>
|
||||
<div class="mt-6 text-right">
|
||||
<button class="btn btn-blue btn-sm text-right" type="submit">Save</button>
|
||||
<button class="btn btn-blue btn-sm text-right" type="submit">{{ $t('strings.save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -57,7 +57,7 @@
|
|||
this.$data.password = '';
|
||||
})
|
||||
.then(() => {
|
||||
this.success('Your email address has been updated.');
|
||||
this.success(this.$t('dashboard.account.email.updated'));
|
||||
})
|
||||
.catch(error => {
|
||||
if (!error.response) {
|
||||
|
@ -79,7 +79,3 @@
|
|||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue