2023-03-17 15:13:37 +00:00
|
|
|
<script setup lang="ts">
|
2023-03-03 15:54:28 +00:00
|
|
|
// import { Head, Link, useForm } from '@inertiajs/inertia-vue3';
|
2023-12-29 14:54:49 +00:00
|
|
|
import { useForm, router } from '@inertiajs/vue3';
|
2023-03-17 15:13:37 +00:00
|
|
|
// import { reactive } from 'vue';
|
2023-03-03 15:54:28 +00:00
|
|
|
import {
|
2023-06-27 16:23:18 +00:00
|
|
|
mdiAccount,
|
2023-12-12 14:22:25 +00:00
|
|
|
// mdiAccountCircle,
|
2023-06-27 16:23:18 +00:00
|
|
|
mdiLock,
|
2023-12-12 14:22:25 +00:00
|
|
|
// mdiMail,
|
2023-06-27 16:23:18 +00:00
|
|
|
mdiAsterisk,
|
|
|
|
mdiFormTextboxPassword,
|
|
|
|
mdiArrowLeftBoldOutline,
|
2023-12-29 14:54:49 +00:00
|
|
|
mdiAlertBoxOutline,
|
|
|
|
mdiInformation
|
2023-03-03 15:54:28 +00:00
|
|
|
} from '@mdi/js';
|
|
|
|
import SectionMain from '@/Components/SectionMain.vue';
|
|
|
|
import CardBox from '@/Components/CardBox.vue';
|
|
|
|
import BaseDivider from '@/Components/BaseDivider.vue';
|
|
|
|
import FormField from '@/Components/FormField.vue';
|
|
|
|
import FormControl from '@/Components/FormControl.vue';
|
|
|
|
import BaseButton from '@/Components/BaseButton.vue';
|
|
|
|
import BaseButtons from '@/Components/BaseButtons.vue';
|
2023-12-29 14:54:49 +00:00
|
|
|
import NotificationBar from '@/Components/NotificationBar.vue';
|
2023-03-03 15:54:28 +00:00
|
|
|
import LayoutAuthenticated from '@/Layouts/LayoutAuthenticated.vue';
|
|
|
|
import SectionTitleLineWithButton from '@/Components/SectionTitleLineWithButton.vue';
|
|
|
|
import { stardust } from '@eidellev/adonis-stardust/client';
|
|
|
|
// import { Inertia } from '@inertiajs/inertia';
|
2023-12-12 14:22:25 +00:00
|
|
|
import { computed, Ref } from 'vue';
|
|
|
|
import { usePage } from '@inertiajs/vue3';
|
|
|
|
import FormValidationErrors from '@/Components/FormValidationErrors.vue';
|
2023-12-29 14:54:49 +00:00
|
|
|
// import { Inertia } from '@inertiajs/inertia';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-12-12 14:22:25 +00:00
|
|
|
|
2023-12-29 14:54:49 +00:00
|
|
|
const props = defineProps({
|
2023-06-27 16:23:18 +00:00
|
|
|
// user will be returned from controller action
|
|
|
|
user: {
|
|
|
|
type: Object,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
2023-12-29 14:54:49 +00:00
|
|
|
twoFactorEnabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
code: {
|
|
|
|
type: Object,
|
|
|
|
},
|
|
|
|
recoveryCodes: {
|
|
|
|
type: Array<string>,
|
|
|
|
default: () => [],
|
|
|
|
},
|
2023-06-27 16:23:18 +00:00
|
|
|
errors: {
|
|
|
|
type: Object,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
2023-03-03 15:54:28 +00:00
|
|
|
});
|
|
|
|
|
2023-12-29 14:54:49 +00:00
|
|
|
// const factorForm = useForm({
|
2023-12-12 14:22:25 +00:00
|
|
|
// login: props.user.login,
|
|
|
|
// email: props.user.email,
|
|
|
|
// });
|
2023-12-29 14:54:49 +00:00
|
|
|
const enableTwoFactorAuthentication = async () => {
|
|
|
|
await router.post(stardust.route('account.password.enable2fa'));
|
|
|
|
};
|
|
|
|
const disableTwoFactorAuthentication = async () => {
|
|
|
|
await router.post(stardust.route('account.password.disable2fa'));
|
|
|
|
};
|
|
|
|
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const passwordForm = useForm({
|
2023-06-27 16:23:18 +00:00
|
|
|
old_password: '',
|
|
|
|
new_password: '',
|
|
|
|
confirm_password: '',
|
2023-03-03 15:54:28 +00:00
|
|
|
});
|
|
|
|
const passwordSubmit = async () => {
|
2023-12-29 14:54:49 +00:00
|
|
|
await passwordForm.post(stardust.route('account.password.store'), {
|
2023-03-03 15:54:28 +00:00
|
|
|
preserveScroll: true,
|
2023-12-12 14:22:25 +00:00
|
|
|
onSuccess: () => {
|
|
|
|
// console.log(resp);
|
2023-03-03 15:54:28 +00:00
|
|
|
passwordForm.reset();
|
2023-06-27 16:23:18 +00:00
|
|
|
},
|
2023-03-03 15:54:28 +00:00
|
|
|
});
|
|
|
|
};
|
2023-12-12 14:22:25 +00:00
|
|
|
|
|
|
|
const flash: Ref<any> = computed(() => {
|
|
|
|
return usePage().props.flash;
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-06-27 16:23:18 +00:00
|
|
|
<LayoutAuthenticated>
|
|
|
|
<SectionMain>
|
|
|
|
<SectionTitleLineWithButton :icon="mdiAccount" title="Profile" main>
|
2023-12-12 14:22:25 +00:00
|
|
|
<BaseButton :route-name="stardust.route('dashboard')" :icon="mdiArrowLeftBoldOutline" label="Back"
|
|
|
|
color="white" rounded-full small />
|
2023-06-27 16:23:18 +00:00
|
|
|
</SectionTitleLineWithButton>
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-12-29 14:54:49 +00:00
|
|
|
<NotificationBar v-if="flash.message" color="success" :icon="mdiAlertBoxOutline">
|
|
|
|
{{ flash.message }}
|
|
|
|
</NotificationBar>
|
2023-06-27 16:23:18 +00:00
|
|
|
<!-- <NotificationBar v-if="$page.props.flash.message" color="success" :icon="mdiAlertBoxOutline">
|
2023-03-03 15:54:28 +00:00
|
|
|
{{ $page.props.flash.message }}
|
2023-03-17 15:13:37 +00:00
|
|
|
</NotificationBar> -->
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-12-12 14:22:25 +00:00
|
|
|
<!-- <div class="grid grid-cols-1 lg:grid-cols-2 gap-6"> -->
|
|
|
|
<div class="grid grid-cols-1 lg:grid-cols-1 gap-6">
|
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
<!-- password form -->
|
|
|
|
<!-- <CardBox title="Edit Profile" :icon="mdiAccountCircle" form @submit.prevent="profileForm.post(route('admin.account.info.store'))"> -->
|
2023-12-12 14:22:25 +00:00
|
|
|
<!-- <CardBox title="Edit Profile" :icon="mdiAccountCircle" form @submit.prevent="profileSubmit()">
|
2023-06-27 16:23:18 +00:00
|
|
|
<FormField label="Login" help="Required. Your login name" :class="{ 'text-red-400': errors.login }">
|
|
|
|
<FormControl v-model="profileForm.login" v-bind:icon="mdiAccount" name="login" required :error="errors.login">
|
|
|
|
<div class="text-red-400 text-sm" v-if="errors.login">
|
|
|
|
{{ errors.login }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField>
|
|
|
|
<FormField label="Email" help="Required. Your e-mail" :class="{ 'text-red-400': errors.email }">
|
|
|
|
<FormControl v-model="profileForm.email" :icon="mdiMail" type="email" name="email" required :error="errors.email">
|
|
|
|
<div class="text-red-400 text-sm" v-if="errors.email">
|
|
|
|
{{ errors.email }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField>
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
<template #footer>
|
|
|
|
<BaseButtons>
|
|
|
|
<BaseButton color="info" type="submit" label="Submit" />
|
|
|
|
</BaseButtons>
|
|
|
|
</template>
|
2023-12-12 14:22:25 +00:00
|
|
|
</CardBox> -->
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
<!-- password form -->
|
|
|
|
<!-- <CardBox title="Change Password" :icon="mdiLock" form @submit.prevent="passwordForm.post(route('admin.account.password.store'), {
|
2023-03-03 15:54:28 +00:00
|
|
|
preserveScroll: true,
|
|
|
|
onSuccess: () => passwordForm.reset(),
|
2023-12-12 14:22:25 +00:00
|
|
|
}) "> -->
|
|
|
|
<CardBox id="passwordForm" title="Change Password" :icon="mdiLock" form @submit.prevent="passwordSubmit()">
|
|
|
|
<FormValidationErrors v-bind:errors="errors" />
|
|
|
|
|
|
|
|
<FormField label="Current password" help="Required. Your current password"
|
|
|
|
:class="{ 'text-red-400': passwordForm.errors.old_password }">
|
|
|
|
<FormControl v-model="passwordForm.old_password" :icon="mdiAsterisk" name="old_password"
|
|
|
|
type="password" required :error="passwordForm.errors.old_password">
|
2023-06-27 16:23:18 +00:00
|
|
|
<div class="text-red-400 text-sm" v-if="passwordForm.errors.old_password">
|
|
|
|
{{ passwordForm.errors.old_password }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField>
|
|
|
|
<BaseDivider />
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-12-12 14:22:25 +00:00
|
|
|
<FormField label="New password" help="Required. New password"
|
|
|
|
:class="{ 'text-red-400': passwordForm.errors.new_password }">
|
|
|
|
<FormControl v-model="passwordForm.new_password" :icon="mdiFormTextboxPassword" name="new_password"
|
|
|
|
type="password" required :error="passwordForm.errors.new_password">
|
2023-06-27 16:23:18 +00:00
|
|
|
<div class="text-red-400 text-sm" v-if="passwordForm.errors.new_password">
|
|
|
|
{{ passwordForm.errors.new_password }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField>
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-12-12 14:22:25 +00:00
|
|
|
<FormField label="Confirm password" help="Required. New password one more time"
|
|
|
|
:class="{ 'text-red-400': passwordForm.errors.confirm_password }">
|
|
|
|
<FormControl v-model="passwordForm.confirm_password" :icon="mdiFormTextboxPassword"
|
|
|
|
name="confirm_password" type="password" required :error="passwordForm.errors.confirm_password">
|
2023-06-27 16:23:18 +00:00
|
|
|
<div class="text-red-400 text-sm" v-if="passwordForm.errors.confirm_password">
|
|
|
|
{{ passwordForm.errors.confirm_password }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField>
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-12-29 14:54:49 +00:00
|
|
|
|
|
|
|
<div v-if="flash && flash.warning" class="flex flex-col mt-6 animate-fade-in">
|
2023-12-12 14:22:25 +00:00
|
|
|
<div class="bg-yellow-500 border-l-4 border-orange-400 text-white p-4" role="alert">
|
|
|
|
<p class="font-bold">Be Warned</p>
|
2023-12-29 14:54:49 +00:00
|
|
|
<p>{{ flash.warning }}</p>
|
2023-12-12 14:22:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<BaseDivider />
|
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
<template #footer>
|
|
|
|
<BaseButtons>
|
2023-12-12 14:22:25 +00:00
|
|
|
<BaseButton type="submit" color="info" label="Change password" />
|
2023-06-27 16:23:18 +00:00
|
|
|
</BaseButtons>
|
|
|
|
</template>
|
|
|
|
</CardBox>
|
2023-12-29 14:54:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- <CardBox title="Edit Profile" :icon="mdiAccountCircle" form @submit.prevent="profileForm.post(route('admin.account.info.store'))"> -->
|
|
|
|
<CardBox v-if="!props.twoFactorEnabled" title="Two-Factor Authentication" :icon="mdiInformation" form
|
|
|
|
@submit.prevent="enableTwoFactorAuthentication()">
|
|
|
|
<!-- <FormField label="Login" help="Required. Your login name" :class="{ 'text-red-400': errors.login }">
|
|
|
|
<FormControl v-model="factorForm.login" v-bind:icon="mdiAccount" name="login" required :error="errors.login">
|
|
|
|
<div class="text-red-400 text-sm" v-if="errors.login">
|
|
|
|
{{ errors.login }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField>
|
|
|
|
<FormField label="Email" help="Required. Your e-mail" :class="{ 'text-red-400': errors.email }">
|
|
|
|
<FormControl v-model="factorForm.email" :icon="mdiMail" type="email" name="email" required :error="errors.email">
|
|
|
|
<div class="text-red-400 text-sm" v-if="errors.email">
|
|
|
|
{{ errors.email }}
|
|
|
|
</div>
|
|
|
|
</FormControl>
|
|
|
|
</FormField> -->
|
|
|
|
|
|
|
|
<div class="text-lg font-medium text-gray-900">
|
|
|
|
You have not enabled two factor authentication.
|
|
|
|
</div>
|
|
|
|
<div class="text-sm text-gray-600">
|
|
|
|
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.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
<BaseButtons>
|
|
|
|
<BaseButton color="info" type="submit" label="Enable" />
|
|
|
|
</BaseButtons>
|
|
|
|
</template>
|
|
|
|
</CardBox>
|
|
|
|
|
|
|
|
<CardBox v-else-if="props.twoFactorEnabled" title="Two-Factor Authentication" :icon="mdiInformation" form @submit.prevent="disableTwoFactorAuthentication()">
|
|
|
|
<!-- <div class="w-1/2 space-y-4 bg-gray-100 p-8"> -->
|
|
|
|
<h3 class="text-lg font-medium text-gray-900">
|
|
|
|
You have 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="code">
|
|
|
|
<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">
|
|
|
|
<img :src="code?.svg" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- @if(recoveryCodes) -->
|
|
|
|
<div v-if="recoveryCodes" 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="mt-4 grid max-w-xl gap-1 rounded-lg bg-gray-100 px-4 py-4 font-mono text-sm">
|
|
|
|
@each(code in recoveryCodes)
|
|
|
|
<div>
|
|
|
|
{{ code }}
|
|
|
|
</div>
|
|
|
|
@endeach
|
|
|
|
</div> -->
|
|
|
|
<!-- @endif -->
|
|
|
|
|
|
|
|
<div class="flex justify-between">
|
|
|
|
<!-- <form action="{{ route('UserController.fetchRecoveryCodes') }}" method="GET">
|
|
|
|
<button type="submit" class="px-auto items-center rounded border border-gray-300 bg-white px-2.5 py-1.5 text-xs
|
|
|
|
font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none
|
|
|
|
">
|
|
|
|
Show Recovery Codes
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
<form action="{{ route('UserController.disableTwoFactorAuthentication') }}" method="POST">
|
|
|
|
<button type="submit" class="px-auto items-center rounded border border-gray-300 bg-white px-2.5 py-1.5 text-xs
|
|
|
|
font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none
|
|
|
|
">
|
|
|
|
Disable
|
|
|
|
</button>
|
|
|
|
</form> -->
|
|
|
|
<BaseButton color="info" type="submit" label="Disable" />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- </div> -->
|
|
|
|
</CardBox>
|
|
|
|
|
2023-06-27 16:23:18 +00:00
|
|
|
</div>
|
|
|
|
</SectionMain>
|
|
|
|
</LayoutAuthenticated>
|
2023-03-03 15:54:28 +00:00
|
|
|
</template>
|