n8n/packages/editor-ui/src/views/ForgotMyPasswordView.vue
Csaba Tuncsik 51fb913d37
refactor(editor): Turn showMessage mixin to composable (#6081) (#6244)
* refactor(editor): Turn showMessage mixin to composable (#6081)

* refactor(editor): move $getExecutionError from showMessages mixin to pushConnection (it is used there only)

* refactor(editor): resolve showMessage mixin methods

* fix(editor): use composable instead of mixin

* fix(editor): resolve conflicts

* fix(editor): replace clearAllStickyNotifications

* fix(editor): replace confirmMessage

* fix(editor): replace confirmMessage

* fix(editor): replace confirmMessage

* fix(editor): remove last confirmMessage usage

* fix(editor): remove $prompt usage

* fix(editor): remove $show methods

* fix(editor): lint fix

* fix(editor): lint fix

* fix(editor): fixes after review

* fix(editor): Fix external hook call in App

* fix(editor): mixins & composables

* fix: add pushConnection setup composables to components as well

* fix(editor): mixins & composables

* fix(editor): mixins & composables

* fix: add void on non-await async calls

* fix: fix close without connecting confirmation

* fix: remove .only

---------

Co-authored-by: Alex Grozav <alex@grozav.com>
2023-05-15 19:41:13 +03:00

105 lines
2.5 KiB
Vue

<template>
<AuthView :form="formConfig" :formLoading="loading" @submit="onSubmit" />
</template>
<script lang="ts">
import AuthView from './AuthView.vue';
import { useToast } from '@/composables';
import { defineComponent } from 'vue';
import type { IFormBoxConfig } from '@/Interface';
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/settings.store';
import { useUsersStore } from '@/stores/users.store';
export default defineComponent({
name: 'ForgotMyPasswordView',
components: {
AuthView,
},
setup() {
return {
...useToast(),
};
},
data() {
return {
loading: false,
};
},
computed: {
...mapStores(useSettingsStore, useUsersStore),
formConfig(): IFormBoxConfig {
const EMAIL_INPUTS: IFormBoxConfig['inputs'] = [
{
name: 'email',
properties: {
label: this.$locale.baseText('auth.email'),
type: 'email',
required: true,
validationRules: [{ name: 'VALID_EMAIL' }],
autocomplete: 'email',
capitalize: true,
},
},
];
const NO_SMTP_INPUTS: IFormBoxConfig['inputs'] = [
{
name: 'no-smtp-warning',
properties: {
label: this.$locale.baseText('forgotPassword.noSMTPToSendEmailWarning'),
type: 'info',
},
},
];
const DEFAULT_FORM_CONFIG = {
title: this.$locale.baseText('forgotPassword.recoverPassword'),
redirectText: this.$locale.baseText('forgotPassword.returnToSignIn'),
redirectLink: '/signin',
};
if (this.settingsStore.isSmtpSetup) {
return {
...DEFAULT_FORM_CONFIG,
buttonText: this.$locale.baseText('forgotPassword.getRecoveryLink'),
inputs: EMAIL_INPUTS,
};
}
return {
...DEFAULT_FORM_CONFIG,
inputs: NO_SMTP_INPUTS,
};
},
},
methods: {
async onSubmit(values: { email: string }) {
try {
this.loading = true;
await this.usersStore.sendForgotPasswordEmail(values);
this.showMessage({
type: 'success',
title: this.$locale.baseText('forgotPassword.recoveryEmailSent'),
message: this.$locale.baseText('forgotPassword.emailSentIfExists', {
interpolate: { email: values.email },
}),
});
} catch (error) {
let message = this.$locale.baseText('forgotPassword.smtpErrorContactAdministrator');
if (error.httpStatusCode === 422) {
message = this.$locale.baseText(error.message);
}
this.showMessage({
type: 'error',
title: this.$locale.baseText('forgotPassword.sendingEmailError'),
message,
});
}
this.loading = false;
},
},
});
</script>