mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 02:04:26 +08:00
migrate forget password / reset password / verify email page to composition API and typescript
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
<div class="layout-wrapper">
|
<div class="layout-wrapper">
|
||||||
<router-link to="/">
|
<router-link to="/">
|
||||||
<div class="auth-logo d-flex align-start gap-x-3">
|
<div class="auth-logo d-flex align-start gap-x-3">
|
||||||
<img alt="logo" class="login-page-logo" :src="ezBookkeepingLogoPath" />
|
<img alt="logo" class="login-page-logo" :src="APPLICATION_LOGO_PATH" />
|
||||||
<h1 class="font-weight-medium leading-normal text-2xl">{{ $t('global.app.title') }}</h1>
|
<h1 class="font-weight-medium leading-normal text-2xl">{{ tt('global.app.title') }}</h1>
|
||||||
</div>
|
</div>
|
||||||
</router-link>
|
</router-link>
|
||||||
<v-row no-gutters class="auth-wrapper">
|
<v-row no-gutters class="auth-wrapper">
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
<div class="d-flex align-center justify-center h-100">
|
<div class="d-flex align-center justify-center h-100">
|
||||||
<v-card variant="flat" class="w-100 mt-0 px-4 pt-12" max-width="500">
|
<v-card variant="flat" class="w-100 mt-0 px-4 pt-12" max-width="500">
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<h4 class="text-h4 mb-2">{{ $t('Forget Password?') }}</h4>
|
<h4 class="text-h4 mb-2">{{ tt('Forget Password?') }}</h4>
|
||||||
<p class="mb-0">{{ $t('Please enter your email address used for registration and we\'ll send you an email with a reset password link') }}</p>
|
<p class="mb-0">{{ tt('Please enter your email address used for registration and we\'ll send you an email with a reset password link') }}</p>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
||||||
<v-card-text class="pb-0 mb-6">
|
<v-card-text class="pb-0 mb-6">
|
||||||
@@ -35,8 +35,8 @@
|
|||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
autofocus="autofocus"
|
autofocus="autofocus"
|
||||||
:disabled="requesting"
|
:disabled="requesting"
|
||||||
:label="$t('E-mail')"
|
:label="tt('E-mail')"
|
||||||
:placeholder="$t('Your email address')"
|
:placeholder="tt('Your email address')"
|
||||||
v-model="email"
|
v-model="email"
|
||||||
@keyup.enter="requestResetPassword"
|
@keyup.enter="requestResetPassword"
|
||||||
/>
|
/>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-btn block type="submit" :disabled="!email || requesting" @click="requestResetPassword">
|
<v-btn block type="submit" :disabled="!email || requesting" @click="requestResetPassword">
|
||||||
{{ $t('Send Reset Link') }}
|
{{ tt('Send Reset Link') }}
|
||||||
<v-progress-circular indeterminate size="22" class="ml-2" v-if="requesting"></v-progress-circular>
|
<v-progress-circular indeterminate size="22" class="ml-2" v-if="requesting"></v-progress-circular>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<router-link class="d-flex align-center justify-center" to="/login"
|
<router-link class="d-flex align-center justify-center" to="/login"
|
||||||
:class="{ 'disabled': requesting }">
|
:class="{ 'disabled': requesting }">
|
||||||
<v-icon :icon="icons.left"/>
|
<v-icon :icon="icons.left"/>
|
||||||
<span>{{ $t('Back to login page') }}</span>
|
<span>{{ tt('Back to login page') }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -105,83 +105,77 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
|
import ConfirmDialog from '@/components/desktop/ConfirmDialog.vue';
|
||||||
|
import SnackBar from '@/components/desktop/SnackBar.vue';
|
||||||
|
|
||||||
|
import { ref, computed, useTemplateRef } from 'vue';
|
||||||
import { useTheme } from 'vuetify';
|
import { useTheme } from 'vuetify';
|
||||||
|
|
||||||
import { mapStores } from 'pinia';
|
import type { LanguageOption } from '@/locales/index.ts';
|
||||||
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
|
|
||||||
import { useRootStore } from '@/stores/index.js';
|
import { useRootStore } from '@/stores/index.js';
|
||||||
import { useSettingsStore } from '@/stores/setting.ts';
|
import { useSettingsStore } from '@/stores/setting.ts';
|
||||||
|
|
||||||
import { APPLICATION_LOGO_PATH } from '@/consts/asset.ts';
|
import { APPLICATION_LOGO_PATH } from '@/consts/asset.ts';
|
||||||
import { ThemeType } from '@/core/theme.ts';
|
import { ThemeType } from '@/core/theme.ts';
|
||||||
|
import { getVersion } from '@/lib/version.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiChevronLeft,
|
mdiChevronLeft,
|
||||||
} from '@mdi/js';
|
} from '@mdi/js';
|
||||||
|
|
||||||
export default {
|
type ConfirmDialogType = InstanceType<typeof ConfirmDialog>;
|
||||||
data() {
|
type SnackBarType = InstanceType<typeof SnackBar>;
|
||||||
return {
|
|
||||||
email: '',
|
|
||||||
requesting: false,
|
|
||||||
icons: {
|
|
||||||
left: mdiChevronLeft
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapStores(useRootStore, useSettingsStore),
|
|
||||||
ezBookkeepingLogoPath() {
|
|
||||||
return APPLICATION_LOGO_PATH;
|
|
||||||
},
|
|
||||||
version() {
|
|
||||||
return 'v' + this.$version;
|
|
||||||
},
|
|
||||||
allLanguages() {
|
|
||||||
return this.$locale.getAllLanguageInfoArray(false);
|
|
||||||
},
|
|
||||||
isDarkMode() {
|
|
||||||
return this.globalTheme.global.name.value === ThemeType.Dark;
|
|
||||||
},
|
|
||||||
currentLanguageName() {
|
|
||||||
return this.$locale.getCurrentLanguageDisplayName();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setup() {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return {
|
const theme = useTheme();
|
||||||
globalTheme: theme
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
requestResetPassword() {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
if (!self.email) {
|
const { tt, getCurrentLanguageDisplayName, getAllLanguageOptions, setLanguage } = useI18n();
|
||||||
self.$refs.snackbar.showMessage('Email address cannot be blank');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.requesting = true;
|
const rootStore = useRootStore();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
self.rootStore.requestResetPassword({
|
const icons = {
|
||||||
email: self.email
|
left: mdiChevronLeft
|
||||||
}).then(() => {
|
};
|
||||||
self.requesting = false;
|
|
||||||
self.$refs.snackbar.showMessage('Password reset email has been sent');
|
|
||||||
}).catch(error => {
|
|
||||||
self.requesting = false;
|
|
||||||
|
|
||||||
if (!error.processed) {
|
const version = `v${getVersion()}`;
|
||||||
self.$refs.snackbar.showError(error);
|
|
||||||
}
|
const confirmDialog = useTemplateRef<ConfirmDialogType>('confirmDialog');
|
||||||
});
|
const snackbar = useTemplateRef<SnackBarType>('snackbar');
|
||||||
},
|
|
||||||
changeLanguage(locale) {
|
const email = ref<string>('');
|
||||||
const localeDefaultSettings = this.$locale.setLanguage(locale);
|
const requesting = ref<boolean>(false);
|
||||||
this.settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
|
||||||
}
|
const allLanguages = computed<LanguageOption[]>(() => getAllLanguageOptions(false));
|
||||||
|
const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType.Dark);
|
||||||
|
const currentLanguageName = computed<string>(() => getCurrentLanguageDisplayName());
|
||||||
|
|
||||||
|
function requestResetPassword(): void {
|
||||||
|
if (!email.value) {
|
||||||
|
snackbar.value?.showMessage('Email address cannot be blank');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requesting.value = true;
|
||||||
|
|
||||||
|
rootStore.requestResetPassword({
|
||||||
|
email: email.value
|
||||||
|
}).then(() => {
|
||||||
|
requesting.value = false;
|
||||||
|
snackbar.value?.showMessage('Password reset email has been sent');
|
||||||
|
}).catch(error => {
|
||||||
|
requesting.value = false;
|
||||||
|
|
||||||
|
if (!error.processed) {
|
||||||
|
snackbar.value?.showError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeLanguage(locale: string): void {
|
||||||
|
const localeDefaultSettings = setLanguage(locale);
|
||||||
|
settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<div class="layout-wrapper">
|
<div class="layout-wrapper">
|
||||||
<router-link to="/">
|
<router-link to="/">
|
||||||
<div class="auth-logo d-flex align-start gap-x-3">
|
<div class="auth-logo d-flex align-start gap-x-3">
|
||||||
<img alt="logo" class="login-page-logo" :src="ezBookkeepingLogoPath" />
|
<img alt="logo" class="login-page-logo" :src="APPLICATION_LOGO_PATH" />
|
||||||
<h1 class="font-weight-medium leading-normal text-2xl">{{ $t('global.app.title') }}</h1>
|
<h1 class="font-weight-medium leading-normal text-2xl">{{ tt('global.app.title') }}</h1>
|
||||||
</div>
|
</div>
|
||||||
</router-link>
|
</router-link>
|
||||||
<v-row no-gutters class="auth-wrapper">
|
<v-row no-gutters class="auth-wrapper">
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
<div class="d-flex align-center justify-center h-100">
|
<div class="d-flex align-center justify-center h-100">
|
||||||
<v-card variant="flat" class="w-100 mt-0 px-4 pt-12" max-width="500">
|
<v-card variant="flat" class="w-100 mt-0 px-4 pt-12" max-width="500">
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<h4 class="text-h4 mb-2">{{ $t('Reset Password') }}</h4>
|
<h4 class="text-h4 mb-2">{{ tt('Reset Password') }}</h4>
|
||||||
<p class="mb-0">{{ $t('Please enter your email address again, and input the new password.') }}</p>
|
<p class="mb-0">{{ tt('Please re-enter your email address, and then enter a new password.') }}</p>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
||||||
<v-card-text class="pb-0 mb-6">
|
<v-card-text class="pb-0 mb-6">
|
||||||
@@ -35,10 +35,10 @@
|
|||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
autofocus="autofocus"
|
autofocus="autofocus"
|
||||||
:disabled="updating"
|
:disabled="updating"
|
||||||
:label="$t('E-mail')"
|
:label="tt('E-mail')"
|
||||||
:placeholder="$t('Your email address')"
|
:placeholder="tt('Your email address')"
|
||||||
v-model="email"
|
v-model="email"
|
||||||
@keyup.enter="$refs.passwordInput.focus()"
|
@keyup.enter="passwordInput?.focus()"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
@@ -48,10 +48,10 @@
|
|||||||
ref="passwordInput"
|
ref="passwordInput"
|
||||||
type="password"
|
type="password"
|
||||||
:disabled="updating"
|
:disabled="updating"
|
||||||
:label="$t('Password')"
|
:label="tt('Password')"
|
||||||
:placeholder="$t('Your password')"
|
:placeholder="tt('Your password')"
|
||||||
v-model="newPassword"
|
v-model="newPassword"
|
||||||
@keyup.enter="$refs.confirmPasswordInput.focus()"
|
@keyup.enter="confirmPasswordInput?.focus()"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@
|
|||||||
ref="confirmPasswordInput"
|
ref="confirmPasswordInput"
|
||||||
type="password"
|
type="password"
|
||||||
:disabled="updating"
|
:disabled="updating"
|
||||||
:label="$t('Confirm Password')"
|
:label="tt('Confirm Password')"
|
||||||
:placeholder="$t('Re-enter the password')"
|
:placeholder="tt('Re-enter the password')"
|
||||||
v-model="confirmPassword"
|
v-model="confirmPassword"
|
||||||
@keyup.enter="resetPassword"
|
@keyup.enter="resetPassword"
|
||||||
/>
|
/>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-btn block :disabled="!email || !newPassword || !confirmPassword || updating" @click="resetPassword">
|
<v-btn block :disabled="!email || !newPassword || !confirmPassword || updating" @click="resetPassword">
|
||||||
{{ $t('Update Password') }}
|
{{ tt('Update Password') }}
|
||||||
<v-progress-circular indeterminate size="22" class="ml-2" v-if="updating"></v-progress-circular>
|
<v-progress-circular indeterminate size="22" class="ml-2" v-if="updating"></v-progress-circular>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
<router-link class="d-flex align-center justify-center" to="/login"
|
<router-link class="d-flex align-center justify-center" to="/login"
|
||||||
:class="{ 'disabled': updating }">
|
:class="{ 'disabled': updating }">
|
||||||
<v-icon :icon="icons.left"/>
|
<v-icon :icon="icons.left"/>
|
||||||
<span>{{ $t('Back to login page') }}</span>
|
<span>{{ tt('Back to login page') }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -130,116 +130,119 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
|
import { VTextField } from 'vuetify/components/VTextField';
|
||||||
|
import ConfirmDialog from '@/components/desktop/ConfirmDialog.vue';
|
||||||
|
import SnackBar from '@/components/desktop/SnackBar.vue';
|
||||||
|
|
||||||
|
import { ref, computed, useTemplateRef } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import { useTheme } from 'vuetify';
|
import { useTheme } from 'vuetify';
|
||||||
|
|
||||||
import { mapStores } from 'pinia';
|
import type { LanguageOption } from '@/locales/index.ts';
|
||||||
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
|
|
||||||
import { useRootStore } from '@/stores/index.js';
|
import { useRootStore } from '@/stores/index.js';
|
||||||
import { useSettingsStore } from '@/stores/setting.ts';
|
import { useSettingsStore } from '@/stores/setting.ts';
|
||||||
|
|
||||||
import { APPLICATION_LOGO_PATH } from '@/consts/asset.ts';
|
import { APPLICATION_LOGO_PATH } from '@/consts/asset.ts';
|
||||||
import { ThemeType } from '@/core/theme.ts';
|
import { ThemeType } from '@/core/theme.ts';
|
||||||
|
import { getVersion } from '@/lib/version.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiChevronLeft
|
mdiChevronLeft
|
||||||
} from '@mdi/js';
|
} from '@mdi/js';
|
||||||
|
|
||||||
export default {
|
type ConfirmDialogType = InstanceType<typeof ConfirmDialog>;
|
||||||
props: [
|
type SnackBarType = InstanceType<typeof SnackBar>;
|
||||||
'token'
|
|
||||||
],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
email: '',
|
|
||||||
newPassword: '',
|
|
||||||
confirmPassword: '',
|
|
||||||
updating: false,
|
|
||||||
passwordChanged: false,
|
|
||||||
icons: {
|
|
||||||
left: mdiChevronLeft
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapStores(useRootStore, useSettingsStore),
|
|
||||||
inputProblemMessage() {
|
|
||||||
if (!this.email) {
|
|
||||||
return 'Email address cannot be blank';
|
|
||||||
} else if (!this.newPassword && !this.confirmPassword) {
|
|
||||||
return 'Nothing has been modified';
|
|
||||||
} else if (!this.newPassword && this.confirmPassword) {
|
|
||||||
return 'New password cannot be blank';
|
|
||||||
} else if (this.newPassword && !this.confirmPassword) {
|
|
||||||
return 'Password confirmation cannot be blank';
|
|
||||||
} else if (this.newPassword && this.confirmPassword && this.newPassword !== this.confirmPassword) {
|
|
||||||
return 'Password and password confirmation do not match';
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ezBookkeepingLogoPath() {
|
|
||||||
return APPLICATION_LOGO_PATH;
|
|
||||||
},
|
|
||||||
version() {
|
|
||||||
return 'v' + this.$version;
|
|
||||||
},
|
|
||||||
allLanguages() {
|
|
||||||
return this.$locale.getAllLanguageInfoArray(false);
|
|
||||||
},
|
|
||||||
isDarkMode() {
|
|
||||||
return this.globalTheme.global.name.value === ThemeType.Dark;
|
|
||||||
},
|
|
||||||
currentLanguageName() {
|
|
||||||
return this.$locale.getCurrentLanguageDisplayName();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setup() {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return {
|
const props = defineProps<{
|
||||||
globalTheme: theme
|
token: string;
|
||||||
};
|
}>();
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
resetPassword() {
|
|
||||||
const self = this;
|
|
||||||
self.passwordChanged = false;
|
|
||||||
|
|
||||||
const problemMessage = self.inputProblemMessage;
|
const router = useRouter();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
if (problemMessage) {
|
const { tt, getCurrentLanguageDisplayName, getAllLanguageOptions, setLanguage } = useI18n();
|
||||||
self.$refs.snackbar.showMessage(problemMessage);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.updating = true;
|
const rootStore = useRootStore();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
self.rootStore.resetPassword({
|
const icons = {
|
||||||
token: self.token,
|
left: mdiChevronLeft
|
||||||
email: self.email,
|
};
|
||||||
password: self.newPassword
|
|
||||||
}).then(() => {
|
|
||||||
self.updating = false;
|
|
||||||
self.passwordChanged = true;
|
|
||||||
self.$refs.snackbar.showMessage('Password has been updated');
|
|
||||||
}).catch(error => {
|
|
||||||
self.updating = false;
|
|
||||||
self.passwordChanged = false;
|
|
||||||
|
|
||||||
if (!error.processed) {
|
const version = `v${getVersion()}`;
|
||||||
self.$refs.snackbar.showError(error);
|
|
||||||
}
|
const passwordInput = useTemplateRef<VTextField>('passwordInput');
|
||||||
});
|
const confirmPasswordInput = useTemplateRef<VTextField>('confirmPasswordInput');
|
||||||
},
|
const confirmDialog = useTemplateRef<ConfirmDialogType>('confirmDialog');
|
||||||
onSnackbarShowStateChanged(newValue) {
|
const snackbar = useTemplateRef<SnackBarType>('snackbar');
|
||||||
if (!newValue && this.passwordChanged) {
|
|
||||||
this.$router.replace('/login');
|
const email = ref<string>('');
|
||||||
}
|
const newPassword = ref<string>('');
|
||||||
},
|
const confirmPassword = ref<string>('');
|
||||||
changeLanguage(locale) {
|
const updating = ref<boolean>(false);
|
||||||
const localeDefaultSettings = this.$locale.setLanguage(locale);
|
const passwordChanged = ref<boolean>(false);
|
||||||
this.settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
|
||||||
}
|
const allLanguages = computed<LanguageOption[]>(() => getAllLanguageOptions(false));
|
||||||
|
const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType.Dark);
|
||||||
|
const currentLanguageName = computed<string>(() => getCurrentLanguageDisplayName());
|
||||||
|
|
||||||
|
const inputProblemMessage = computed<string | null>(() => {
|
||||||
|
if (!email.value) {
|
||||||
|
return 'Email address cannot be blank';
|
||||||
|
} else if (!newPassword.value && !confirmPassword.value) {
|
||||||
|
return 'Nothing has been modified';
|
||||||
|
} else if (!newPassword.value && confirmPassword.value) {
|
||||||
|
return 'New password cannot be blank';
|
||||||
|
} else if (newPassword.value && !confirmPassword.value) {
|
||||||
|
return 'Password confirmation cannot be blank';
|
||||||
|
} else if (newPassword.value && confirmPassword.value && newPassword.value !== confirmPassword.value) {
|
||||||
|
return 'Password and password confirmation do not match';
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function changeLanguage(locale: string): void {
|
||||||
|
const localeDefaultSettings = setLanguage(locale);
|
||||||
|
settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSnackbarShowStateChanged(newValue: boolean): void {
|
||||||
|
if (!newValue && passwordChanged.value) {
|
||||||
|
router.replace('/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetPassword(): void {
|
||||||
|
passwordChanged.value = false;
|
||||||
|
|
||||||
|
const problemMessage = inputProblemMessage.value;
|
||||||
|
|
||||||
|
if (problemMessage) {
|
||||||
|
snackbar.value?.showMessage(problemMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updating.value = true;
|
||||||
|
|
||||||
|
rootStore.resetPassword({
|
||||||
|
token: props.token,
|
||||||
|
email: email.value,
|
||||||
|
password: newPassword.value
|
||||||
|
}).then(() => {
|
||||||
|
updating.value = false;
|
||||||
|
passwordChanged.value = true;
|
||||||
|
snackbar.value?.showMessage('Password has been updated');
|
||||||
|
}).catch(error => {
|
||||||
|
updating.value = false;
|
||||||
|
passwordChanged.value = false;
|
||||||
|
|
||||||
|
if (!error.processed) {
|
||||||
|
snackbar.value?.showError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<div class="layout-wrapper">
|
<div class="layout-wrapper">
|
||||||
<router-link to="/">
|
<router-link to="/">
|
||||||
<div class="auth-logo d-flex align-start gap-x-3">
|
<div class="auth-logo d-flex align-start gap-x-3">
|
||||||
<img alt="logo" class="login-page-logo" :src="ezBookkeepingLogoPath" />
|
<img alt="logo" class="login-page-logo" :src="APPLICATION_LOGO_PATH" />
|
||||||
<h1 class="font-weight-medium leading-normal text-2xl">{{ $t('global.app.title') }}</h1>
|
<h1 class="font-weight-medium leading-normal text-2xl">{{ tt('global.app.title') }}</h1>
|
||||||
</div>
|
</div>
|
||||||
</router-link>
|
</router-link>
|
||||||
<v-row no-gutters class="auth-wrapper">
|
<v-row no-gutters class="auth-wrapper">
|
||||||
@@ -22,32 +22,32 @@
|
|||||||
<div class="d-flex align-center justify-center h-100">
|
<div class="d-flex align-center justify-center h-100">
|
||||||
<v-card variant="flat" class="w-100 mt-0 px-4 pt-12" max-width="500">
|
<v-card variant="flat" class="w-100 mt-0 px-4 pt-12" max-width="500">
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<h4 class="text-h4 mb-2">{{ $t('Verify your email') }}</h4>
|
<h4 class="text-h4 mb-2">{{ tt('Verify your email') }}</h4>
|
||||||
<p class="mb-0" v-if="token && loading">{{ $t('Verifying...') }}</p>
|
<p class="mb-0" v-if="token && loading">{{ tt('Verifying...') }}</p>
|
||||||
<p class="mb-0" v-if="token && verified">{{ $t('Email address is verified') }}</p>
|
<p class="mb-0" v-if="token && verified">{{ tt('Email address is verified') }}</p>
|
||||||
<p class="mb-0" v-if="token && !verified && errorMessage">{{ errorMessage }}</p>
|
<p class="mb-0" v-if="token && !verified && errorMessage">{{ errorMessage }}</p>
|
||||||
<p class="mb-0" v-if="!token && !email">{{ $t('Parameter Invalid') }}</p>
|
<p class="mb-0" v-if="!token && !email">{{ tt('Parameter Invalid') }}</p>
|
||||||
<p class="mb-0" v-if="!token && email">{{ $t(hasValidEmailVerifyToken ? 'format.misc.accountActivationAndResendValidationEmailTip' : 'format.misc.resendValidationEmailTip', { email: email }) }}</p>
|
<p class="mb-0" v-if="!token && email">{{ tt(hasValidEmailVerifyToken ? 'format.misc.accountActivationAndResendValidationEmailTip' : 'format.misc.resendValidationEmailTip', { email: email }) }}</p>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
||||||
<v-card-text class="pb-0 mb-6">
|
<v-card-text class="pb-0 mb-6">
|
||||||
<v-form>
|
<v-form>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col cols="12" v-if="!loading && !token && email && isUserVerifyEmailEnabled">
|
<v-col cols="12" v-if="!loading && !token && email && isUserVerifyEmailEnabled()">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
autocomplete="password"
|
autocomplete="password"
|
||||||
type="password"
|
type="password"
|
||||||
:disabled="loading || resending"
|
:disabled="loading || resending"
|
||||||
:label="$t('Password')"
|
:label="tt('Password')"
|
||||||
:placeholder="$t('Your password')"
|
:placeholder="tt('Your password')"
|
||||||
v-model="password"
|
v-model="password"
|
||||||
@keyup.enter="resendEmail"
|
@keyup.enter="resendEmail"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
<v-col cols="12" v-if="!loading && !token && email && isUserVerifyEmailEnabled">
|
<v-col cols="12" v-if="!loading && !token && email && isUserVerifyEmailEnabled()">
|
||||||
<v-btn block type="submit" :disabled="loading || resending || !password" @click="resendEmail">
|
<v-btn block type="submit" :disabled="loading || resending || !password" @click="resendEmail">
|
||||||
{{ $t('Resend Validation Email') }}
|
{{ tt('Resend Validation Email') }}
|
||||||
<v-progress-circular indeterminate size="22" class="ml-2" v-if="resending"></v-progress-circular>
|
<v-progress-circular indeterminate size="22" class="ml-2" v-if="resending"></v-progress-circular>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -56,8 +56,8 @@
|
|||||||
<router-link class="d-flex align-center justify-center" :to="verified ? '/' : '/login'"
|
<router-link class="d-flex align-center justify-center" :to="verified ? '/' : '/login'"
|
||||||
:class="{ 'disabled': loading || resending }">
|
:class="{ 'disabled': loading || resending }">
|
||||||
<v-icon :icon="icons.left"/>
|
<v-icon :icon="icons.left"/>
|
||||||
<span v-if="!verified">{{ $t('Back to login page') }}</span>
|
<span v-if="!verified">{{ tt('Back to login page') }}</span>
|
||||||
<span v-else-if="verified">{{ $t('Back to home page') }}</span>
|
<span v-else-if="verified">{{ tt('Back to home page') }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -109,10 +109,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
|
import ConfirmDialog from '@/components/desktop/ConfirmDialog.vue';
|
||||||
|
import SnackBar from '@/components/desktop/SnackBar.vue';
|
||||||
|
|
||||||
|
import { ref, computed, useTemplateRef } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import { useTheme } from 'vuetify';
|
import { useTheme } from 'vuetify';
|
||||||
|
|
||||||
import { mapStores } from 'pinia';
|
import type { LanguageOption } from '@/locales/index.ts';
|
||||||
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
|
|
||||||
import { useRootStore } from '@/stores/index.js';
|
import { useRootStore } from '@/stores/index.js';
|
||||||
import { useSettingsStore } from '@/stores/setting.ts';
|
import { useSettingsStore } from '@/stores/setting.ts';
|
||||||
|
|
||||||
@@ -120,114 +127,103 @@ import { APPLICATION_LOGO_PATH } from '@/consts/asset.ts';
|
|||||||
import { ThemeType } from '@/core/theme.ts';
|
import { ThemeType } from '@/core/theme.ts';
|
||||||
import { isUserVerifyEmailEnabled } from '@/lib/server_settings.ts';
|
import { isUserVerifyEmailEnabled } from '@/lib/server_settings.ts';
|
||||||
import { isUserLogined } from '@/lib/userstate.ts';
|
import { isUserLogined } from '@/lib/userstate.ts';
|
||||||
|
import { getVersion } from '@/lib/version.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiChevronLeft
|
mdiChevronLeft
|
||||||
} from '@mdi/js';
|
} from '@mdi/js';
|
||||||
|
|
||||||
export default {
|
type ConfirmDialogType = InstanceType<typeof ConfirmDialog>;
|
||||||
props: [
|
type SnackBarType = InstanceType<typeof SnackBar>;
|
||||||
'email',
|
|
||||||
'token',
|
const props = defineProps<{
|
||||||
'hasValidEmailVerifyToken'
|
email: string;
|
||||||
],
|
token: string;
|
||||||
data() {
|
hasValidEmailVerifyToken: boolean;
|
||||||
return {
|
}>();
|
||||||
password: '',
|
|
||||||
loading: true,
|
const router = useRouter();
|
||||||
resending: false,
|
const theme = useTheme();
|
||||||
verified: false,
|
|
||||||
errorMessage: '',
|
const { tt, te, getCurrentLanguageDisplayName, getAllLanguageOptions, setLanguage } = useI18n();
|
||||||
icons: {
|
|
||||||
left: mdiChevronLeft
|
const rootStore = useRootStore();
|
||||||
}
|
const settingsStore = useSettingsStore();
|
||||||
};
|
|
||||||
},
|
const icons = {
|
||||||
computed: {
|
left: mdiChevronLeft
|
||||||
...mapStores(useRootStore, useSettingsStore),
|
};
|
||||||
ezBookkeepingLogoPath() {
|
|
||||||
return APPLICATION_LOGO_PATH;
|
const version = `v${getVersion()}`;
|
||||||
},
|
|
||||||
version() {
|
const confirmDialog = useTemplateRef<ConfirmDialogType>('confirmDialog');
|
||||||
return 'v' + this.$version;
|
const snackbar = useTemplateRef<SnackBarType>('snackbar');
|
||||||
},
|
|
||||||
allLanguages() {
|
const password = ref<string>('');
|
||||||
return this.$locale.getAllLanguageInfoArray(false);
|
const loading = ref<boolean>(true);
|
||||||
},
|
const resending = ref<boolean>(false);
|
||||||
isDarkMode() {
|
const verified = ref<boolean>(false);
|
||||||
return this.globalTheme.global.name.value === ThemeType.Dark;
|
const errorMessage = ref<string>('');
|
||||||
},
|
|
||||||
currentLanguageName() {
|
const allLanguages = computed<LanguageOption[]>(() => getAllLanguageOptions(false));
|
||||||
return this.$locale.getCurrentLanguageDisplayName();
|
const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType.Dark);
|
||||||
},
|
const currentLanguageName = computed<string>(() => getCurrentLanguageDisplayName());
|
||||||
isUserVerifyEmailEnabled() {
|
|
||||||
return isUserVerifyEmailEnabled();
|
function init(): void {
|
||||||
|
verified.value = false;
|
||||||
|
loading.value = true;
|
||||||
|
|
||||||
|
if (!props.token) {
|
||||||
|
loading.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rootStore.verifyEmail({
|
||||||
|
token: props.token,
|
||||||
|
requestNewToken: !isUserLogined()
|
||||||
|
}).then(() => {
|
||||||
|
loading.value = false;
|
||||||
|
verified.value = true;
|
||||||
|
snackbar.value?.showMessage('Email address is verified');
|
||||||
|
}).catch(error => {
|
||||||
|
loading.value = false;
|
||||||
|
verified.value = false;
|
||||||
|
|
||||||
|
if (!error.processed) {
|
||||||
|
errorMessage.value = te(error.message || error);
|
||||||
|
snackbar.value?.showError(error);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
setup() {
|
}
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return {
|
function resendEmail(): void {
|
||||||
globalTheme: theme
|
resending.value = true;
|
||||||
};
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
self.verified = false;
|
rootStore.resendVerifyEmailByUnloginUser({
|
||||||
self.loading = true;
|
email: props.email,
|
||||||
|
password: password.value
|
||||||
|
}).then(() => {
|
||||||
|
resending.value = false;
|
||||||
|
snackbar.value?.showMessage('Validation email has been sent');
|
||||||
|
}).catch(error => {
|
||||||
|
resending.value = false;
|
||||||
|
|
||||||
if (!self.token) {
|
if (!error.processed) {
|
||||||
self.loading = false;
|
snackbar.value?.showError(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
self.rootStore.verifyEmail({
|
function changeLanguage(locale: string): void {
|
||||||
token: self.token,
|
const localeDefaultSettings = setLanguage(locale);
|
||||||
requestNewToken: !isUserLogined()
|
settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
||||||
}).then(() => {
|
}
|
||||||
self.loading = false;
|
|
||||||
self.verified = true;
|
|
||||||
self.$refs.snackbar.showMessage('Email address is verified');
|
|
||||||
}).catch(error => {
|
|
||||||
self.loading = false;
|
|
||||||
self.verified = false;
|
|
||||||
|
|
||||||
if (!error.processed) {
|
function onSnackbarShowStateChanged(newValue: boolean): void {
|
||||||
self.errorMessage = self.$tError(error.message || error);
|
if (!newValue && verified.value && isUserLogined()) {
|
||||||
self.$refs.snackbar.showError(error);
|
router.replace('/');
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
resendEmail() {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
self.resending = true;
|
|
||||||
|
|
||||||
self.rootStore.resendVerifyEmailByUnloginUser({
|
|
||||||
email: self.email,
|
|
||||||
password: self.password
|
|
||||||
}).then(() => {
|
|
||||||
self.resending = false;
|
|
||||||
self.$refs.snackbar.showMessage('Validation email has been sent');
|
|
||||||
}).catch(error => {
|
|
||||||
self.resending = false;
|
|
||||||
|
|
||||||
if (!error.processed) {
|
|
||||||
self.$refs.snackbar.showError(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onSnackbarShowStateChanged(newValue) {
|
|
||||||
if (!newValue && this.verified && isUserLogined()) {
|
|
||||||
this.$router.replace('/');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
changeLanguage(locale) {
|
|
||||||
const localeDefaultSettings = this.$locale.setLanguage(locale);
|
|
||||||
this.settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user