2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
|
|
|
<section>
|
|
|
|
<h1 class="title" v-if="loading">
|
|
|
|
<translate>Your account is being validated</translate>
|
|
|
|
</h1>
|
|
|
|
<div v-else>
|
|
|
|
<div v-if="failed">
|
2019-01-30 15:54:21 +01:00
|
|
|
<b-message :title="$gettext('Error while validating account')" type="is-danger">
|
|
|
|
<translate>Either the account is already validated, either the validation token is incorrect.</translate>
|
2019-01-21 15:08:22 +01:00
|
|
|
</b-message>
|
|
|
|
</div>
|
|
|
|
<h1 class="title" v-else>
|
|
|
|
<translate>Your account has been validated</translate>
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 10:57:14 +01:00
|
|
|
import { VALIDATE_USER } from '@/graphql/user';
|
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
import { AUTH_TOKEN, AUTH_USER_ID } from '@/constants';
|
|
|
|
import { RouteName } from '@/router';
|
|
|
|
import { UserRouteName } from '@/router/user';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class Validate extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) token!: string;
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
failed = false;
|
|
|
|
|
2019-01-30 15:54:21 +01:00
|
|
|
async created() {
|
|
|
|
await this.validateAction();
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async validateAction() {
|
|
|
|
try {
|
2019-01-30 15:54:21 +01:00
|
|
|
const { data } = await this.$apollo.mutate({
|
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-01-30 15:54:21 +01:00
|
|
|
this.saveUserData(data);
|
|
|
|
|
|
|
|
const user = data.validateUser.user;
|
|
|
|
console.log(user);
|
|
|
|
if (user.defaultActor) {
|
2019-02-22 14:55:47 +01:00
|
|
|
this.$router.push({ name: RouteName.HOME });
|
2019-01-30 15:54:21 +01:00
|
|
|
} else { // If the user didn't register any profile yet, let's create one for them
|
2019-02-22 14:55:47 +01:00
|
|
|
this.$router.push({ name: UserRouteName.REGISTER_PROFILE, params: { email: user.email, userAlreadyActivated: 'true' } });
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveUserData({ validateUser: login }) {
|
|
|
|
localStorage.setItem(AUTH_USER_ID, login.user.id);
|
|
|
|
localStorage.setItem(AUTH_TOKEN, login.token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|