2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2019-04-03 17:29:03 +02:00
|
|
|
<section class="container">
|
2019-10-10 14:20:09 +02:00
|
|
|
<div class="columns is-mobile is-centered">
|
|
|
|
<div class="column is-half-desktop">
|
|
|
|
<h1 class="title">
|
|
|
|
{{ $t('Password reset') }}
|
|
|
|
</h1>
|
2019-12-09 21:38:29 +01:00
|
|
|
<b-message
|
|
|
|
title="Error" type="is-danger" v-for="error in errors" :key="error" @close="removeError(error)">
|
|
|
|
{{ error }}
|
|
|
|
</b-message>
|
2019-10-10 14:20:09 +02:00
|
|
|
<form @submit="sendResetPasswordTokenAction" v-if="!validationSent">
|
|
|
|
<b-field label="Email">
|
|
|
|
<b-input aria-required="true" required type="email" v-model="credentials.email"/>
|
|
|
|
</b-field>
|
|
|
|
<p class="control has-text-centered">
|
2019-10-13 17:03:48 +02:00
|
|
|
<b-button type="is-primary" native-type="submit">
|
2019-10-10 14:20:09 +02:00
|
|
|
{{ $t('Send me an email to reset my password') }}
|
|
|
|
</b-button>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
<div v-else>
|
|
|
|
<b-message type="is-success" :closable="false" title="Success">
|
|
|
|
{{ $t('We just sent an email to {email}', {email: credentials.email}) }}
|
|
|
|
</b-message>
|
|
|
|
<b-message type="is-info">
|
|
|
|
{{ $t("Please check your spam folder if you didn't receive the email.") }}
|
|
|
|
</b-message>
|
|
|
|
</div>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 10:57:14 +01:00
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
import { validateEmailField, validateRequiredField } from '@/utils/validators';
|
|
|
|
import { SEND_RESET_PASSWORD } from '@/graphql/auth';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class SendPasswordReset extends Vue {
|
2019-03-22 10:57:14 +01:00
|
|
|
@Prop({ type: String, required: false, default: '' }) email!: string;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
credentials = {
|
2019-03-22 10:57:14 +01:00
|
|
|
email: '',
|
2019-01-21 15:08:22 +01:00
|
|
|
} as { email: string };
|
|
|
|
validationSent: boolean = false;
|
|
|
|
errors: string[] = [];
|
|
|
|
state = {
|
|
|
|
email: {
|
|
|
|
status: null,
|
2019-03-22 10:57:14 +01:00
|
|
|
msg: '',
|
|
|
|
} as { status: boolean | null; msg: string },
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
rules = {
|
|
|
|
required: validateRequiredField,
|
2019-03-22 10:57:14 +01:00
|
|
|
email: validateEmailField,
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.credentials.email = this.email;
|
|
|
|
}
|
|
|
|
|
2019-12-09 21:38:29 +01:00
|
|
|
removeError(message: string) {
|
2019-12-15 22:42:38 +01:00
|
|
|
this.errors.splice(this.errors.indexOf(message));
|
2019-12-09 21:38:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
async sendResetPasswordTokenAction(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: SEND_RESET_PASSWORD,
|
|
|
|
variables: {
|
2019-03-22 10:57:14 +01:00
|
|
|
email: this.credentials.email,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this.validationSent = true;
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
err.graphQLErrors.forEach(({ message }) => {
|
2019-12-15 22:42:38 +01:00
|
|
|
if (this.errors.indexOf(message) < 0) {
|
2019-12-09 21:38:29 +01:00
|
|
|
this.errors.push(message);
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetState() {
|
|
|
|
this.state = {
|
|
|
|
email: {
|
|
|
|
status: null,
|
2019-03-22 10:57:14 +01:00
|
|
|
msg: '',
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2019-10-10 14:20:09 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.container .columns {
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
}
|
|
|
|
</style>
|