2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2019-12-20 13:04:34 +01:00
|
|
|
<section class="section container">
|
2020-11-30 10:24:11 +01:00
|
|
|
<h1 class="title" v-if="loading">
|
|
|
|
{{ $t("Your account is being validated") }}
|
|
|
|
</h1>
|
2019-01-21 15:08:22 +01:00
|
|
|
<div v-else>
|
|
|
|
<div v-if="failed">
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-message
|
|
|
|
:title="$t('Error while validating account')"
|
|
|
|
type="is-danger"
|
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
{{
|
2020-11-30 10:24:11 +01:00
|
|
|
$t(
|
|
|
|
"Either the account is already validated, either the validation token is incorrect."
|
|
|
|
)
|
2020-02-18 08:57:00 +01:00
|
|
|
}}
|
2019-01-21 15:08:22 +01:00
|
|
|
</b-message>
|
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
<h1 class="title" v-else>{{ $t("Your account has been validated") }}</h1>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ICurrentUserRole } from "@/types/enums";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { VALIDATE_USER, UPDATE_CURRENT_USER_CLIENT } from "../../graphql/user";
|
|
|
|
import RouteName from "../../router/name";
|
2020-06-27 19:12:45 +02:00
|
|
|
import { saveUserData, saveTokenData, changeIdentity } from "../../utils/auth";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { ILogin } from "../../types/login.model";
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
@Component({
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: this.$t("Validating account") as string,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})
|
2019-01-21 15:08:22 +01:00
|
|
|
export default class Validate extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) token!: string;
|
|
|
|
|
|
|
|
loading = true;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
failed = false;
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
async created(): Promise<void> {
|
2019-01-30 15:54:21 +01:00
|
|
|
await this.validateAction();
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
async validateAction(): Promise<void> {
|
2019-01-21 15:08:22 +01:00
|
|
|
try {
|
2019-10-07 13:47:46 +02:00
|
|
|
const { data } = await this.$apollo.mutate<{ validateUser: ILogin }>({
|
2019-01-21 15:08:22 +01:00
|
|
|
mutation: VALIDATE_USER,
|
|
|
|
variables: {
|
2019-03-22 10:57:14 +01:00
|
|
|
token: this.token,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
|
2019-10-07 13:47:46 +02:00
|
|
|
if (data) {
|
|
|
|
saveUserData(data.validateUser);
|
2020-06-27 19:12:45 +02:00
|
|
|
saveTokenData(data.validateUser);
|
2019-01-30 15:54:21 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
const { user } = data.validateUser;
|
2019-10-07 13:47:46 +02:00
|
|
|
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
|
|
|
id: user.id,
|
|
|
|
email: user.email,
|
|
|
|
isLoggedIn: true,
|
|
|
|
role: ICurrentUserRole.USER,
|
|
|
|
},
|
2019-10-04 18:28:25 +02:00
|
|
|
});
|
2019-10-07 13:47:46 +02:00
|
|
|
|
|
|
|
if (user.defaultActor) {
|
2020-11-30 10:24:11 +01:00
|
|
|
await changeIdentity(
|
|
|
|
this.$apollo.provider.defaultClient,
|
|
|
|
user.defaultActor
|
|
|
|
);
|
2019-10-07 13:47:46 +02:00
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
2020-02-18 08:57:00 +01:00
|
|
|
} else {
|
|
|
|
// If the user didn't register any profile yet, let's create one for them
|
2019-10-07 13:47:46 +02:00
|
|
|
await this.$router.push({
|
|
|
|
name: RouteName.REGISTER_PROFILE,
|
2020-02-18 08:57:00 +01:00
|
|
|
params: { email: user.email, userAlreadyActivated: "true" },
|
2019-10-07 13:47:46 +02:00
|
|
|
});
|
|
|
|
}
|
2019-01-30 15:54:21 +01:00
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
this.failed = true;
|
|
|
|
} finally {
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|