2019-01-21 14:08:22 +00:00
|
|
|
<template>
|
2019-12-20 12:04:34 +00:00
|
|
|
<section class="section container columns is-mobile is-centered">
|
2019-01-21 14:08:22 +00:00
|
|
|
<div class="card column is-half-desktop">
|
|
|
|
<h1>
|
2019-09-12 09:34:01 +00:00
|
|
|
{{ $t('Password reset') }}
|
2019-01-21 14:08:22 +00:00
|
|
|
</h1>
|
|
|
|
<b-message title="Error" type="is-danger" v-for="error in errors" :key="error">{{ error }}</b-message>
|
|
|
|
<form @submit="resetAction">
|
2019-09-18 15:32:37 +00:00
|
|
|
<b-field :label="$t('Password')">
|
2019-01-21 14:08:22 +00:00
|
|
|
<b-input
|
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
type="password"
|
|
|
|
password-reveal
|
|
|
|
minlength="6"
|
|
|
|
v-model="credentials.password"
|
|
|
|
/>
|
|
|
|
</b-field>
|
2019-09-18 15:32:37 +00:00
|
|
|
<b-field :label="$t('Password (confirmation)')">
|
2019-01-21 14:08:22 +00:00
|
|
|
<b-input
|
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
type="password"
|
|
|
|
password-reveal
|
|
|
|
minlength="6"
|
|
|
|
v-model="credentials.password_confirmation"
|
|
|
|
/>
|
|
|
|
</b-field>
|
|
|
|
<button class="button is-primary">
|
2019-09-12 09:34:01 +00:00
|
|
|
{{ $t('Reset my password') }}
|
2019-01-21 14:08:22 +00:00
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 09:57:14 +00:00
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
import { validateRequiredField } from '@/utils/validators';
|
|
|
|
import { RESET_PASSWORD } from '@/graphql/auth';
|
|
|
|
import { saveUserData } from '@/utils/auth';
|
|
|
|
import { ILogin } from '@/types/login.model';
|
|
|
|
import { RouteName } from '@/router';
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class PasswordReset extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) token!: string;
|
|
|
|
|
|
|
|
credentials = {
|
2019-03-22 09:57:14 +00:00
|
|
|
password: '',
|
|
|
|
password_confirmation: '',
|
2019-01-21 14:08:22 +00:00
|
|
|
} as { password: string; password_confirmation: string };
|
|
|
|
errors: string[] = [];
|
|
|
|
rules = {
|
2019-03-22 09:57:14 +00:00
|
|
|
password_length: (value: string) =>
|
|
|
|
value.length > 6 || 'Password must be at least 6 characters long',
|
2019-01-21 14:08:22 +00:00
|
|
|
required: validateRequiredField,
|
2019-03-22 09:57:14 +00:00
|
|
|
password_equal: (value: string) =>
|
|
|
|
value === this.credentials.password || 'Passwords must be the same',
|
2019-01-21 14:08:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
get samePasswords() {
|
|
|
|
return (
|
|
|
|
this.rules.password_length(this.credentials.password) === true &&
|
|
|
|
this.credentials.password === this.credentials.password_confirmation
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async resetAction(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.errors.splice(0);
|
|
|
|
|
|
|
|
try {
|
2019-09-02 16:52:23 +00:00
|
|
|
const { data } = await this.$apollo.mutate<{ resetPassword: ILogin }>({
|
2019-01-21 14:08:22 +00:00
|
|
|
mutation: RESET_PASSWORD,
|
|
|
|
variables: {
|
|
|
|
password: this.credentials.password,
|
2019-03-22 09:57:14 +00:00
|
|
|
token: this.token,
|
|
|
|
},
|
2019-01-21 14:08:22 +00:00
|
|
|
});
|
2019-09-02 16:52:23 +00:00
|
|
|
if (data == null) {
|
|
|
|
throw new Error('Data is undefined');
|
|
|
|
}
|
2019-01-21 14:08:22 +00:00
|
|
|
|
2019-09-02 16:52:23 +00:00
|
|
|
saveUserData(data.resetPassword);
|
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
2019-01-21 14:08:22 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
err.graphQLErrors.forEach(({ message }) => {
|
|
|
|
this.errors.push(message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|