2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2019-10-10 14:20:09 +02:00
|
|
|
<section class="container">
|
|
|
|
<div class="columns is-mobile is-centered">
|
|
|
|
<div class="column is-half-desktop">
|
2019-01-21 15:08:22 +01:00
|
|
|
<h1 class="title">
|
2019-09-12 11:34:01 +02:00
|
|
|
{{ $t('Register an account on Mobilizon!') }}
|
2019-01-21 15:08:22 +01:00
|
|
|
</h1>
|
2019-10-10 14:20:09 +02:00
|
|
|
<form v-if="!validationSent">
|
|
|
|
<b-field
|
|
|
|
:label="$t('Username')"
|
|
|
|
:type="errors.preferred_username ? 'is-danger' : null"
|
|
|
|
:message="errors.preferred_username"
|
|
|
|
>
|
|
|
|
<b-field>
|
|
|
|
<b-input
|
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
expanded
|
|
|
|
v-model="person.preferredUsername"
|
|
|
|
/>
|
|
|
|
<p class="control">
|
|
|
|
<span class="button is-static">@{{ host }}</span>
|
|
|
|
</p>
|
|
|
|
</b-field>
|
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<b-field :label="$t('Displayed name')">
|
|
|
|
<b-input v-model="person.name"/>
|
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<b-field :label="$t('Description')">
|
|
|
|
<b-input type="textarea" v-model="person.summary"/>
|
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<p class="control has-text-centered">
|
|
|
|
<b-button type="is-primary" size="is-large" @click="submit()">
|
|
|
|
{{ $t('Create my profile') }}
|
|
|
|
</b-button>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<div v-if="validationSent && !userAlreadyActivated">
|
|
|
|
<b-message title="Success" type="is-success" closable="false">
|
|
|
|
<h2 class="title">
|
|
|
|
{{ $t('Your account is nearly ready, {username}', { username: person.preferredUsername }) }}
|
|
|
|
</h2>
|
|
|
|
<p>
|
|
|
|
{{ $t('A validation email was sent to {email}', { email }) }}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{{ $t('Before you can login, you need to click on the link inside it to validate your account') }}
|
|
|
|
</p>
|
|
|
|
</b-message>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-10-10 14:20:09 +02:00
|
|
|
</div>
|
|
|
|
</section>
|
2019-01-21 15:08:22 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 10:57:14 +01:00
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
2019-10-04 18:28:25 +02:00
|
|
|
import { IPerson, Person } from '@/types/actor';
|
|
|
|
import { IDENTITIES, REGISTER_PERSON } from '@/graphql/actor';
|
2019-03-22 10:57:14 +01:00
|
|
|
import { MOBILIZON_INSTANCE_HOST } from '@/api/_entrypoint';
|
|
|
|
import { RouteName } from '@/router';
|
2019-10-04 18:28:25 +02:00
|
|
|
import { changeIdentity } from '@/utils/auth';
|
|
|
|
import { ICurrentUser } from '@/types/current-user.model';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-02-22 14:55:47 +01:00
|
|
|
@Component
|
2019-01-21 15:08:22 +01:00
|
|
|
export default class Register extends Vue {
|
2019-01-30 15:54:21 +01:00
|
|
|
@Prop({ type: String, required: true }) email!: string;
|
|
|
|
@Prop({ type: Boolean, required: false, default: false }) userAlreadyActivated!: boolean;
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
host?: string = MOBILIZON_INSTANCE_HOST;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-10-04 18:28:25 +02:00
|
|
|
person: IPerson = new Person();
|
2019-01-29 11:02:32 +01:00
|
|
|
errors: object = {};
|
2019-01-21 15:08:22 +01:00
|
|
|
validationSent: boolean = false;
|
2019-01-29 11:02:32 +01:00
|
|
|
sendingValidation: boolean = false;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-10-10 14:20:09 +02:00
|
|
|
async created() {
|
2019-10-04 18:33:38 +02:00
|
|
|
// Make sure no one goes to this page if we don't want to
|
|
|
|
if (!this.email) {
|
|
|
|
await this.$router.replace({ name: RouteName.PAGE_NOT_FOUND });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
async submit() {
|
|
|
|
try {
|
2019-01-29 11:02:32 +01:00
|
|
|
this.sendingValidation = true;
|
|
|
|
this.errors = {};
|
2019-10-04 18:28:25 +02:00
|
|
|
const { data } = await this.$apollo.mutate<{ registerPerson: IPerson }>({
|
2019-01-29 11:02:32 +01:00
|
|
|
mutation: REGISTER_PERSON,
|
2019-03-22 10:57:14 +01:00
|
|
|
variables: Object.assign({ email: this.email }, this.person),
|
2019-10-04 18:28:25 +02:00
|
|
|
update: (store, { data }) => {
|
2019-10-07 13:47:46 +02:00
|
|
|
if (this.userAlreadyActivated) {
|
|
|
|
const identitiesData = store.readQuery<{ identities: IPerson[] }>({ query: IDENTITIES });
|
2019-10-04 18:28:25 +02:00
|
|
|
|
2019-10-07 13:47:46 +02:00
|
|
|
if (identitiesData && data) {
|
|
|
|
identitiesData.identities.push(data.registerPerson);
|
|
|
|
store.writeQuery({ query: IDENTITIES, data: identitiesData });
|
|
|
|
}
|
2019-10-04 18:28:25 +02:00
|
|
|
}
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
2019-10-04 18:28:25 +02:00
|
|
|
if (data) {
|
|
|
|
this.validationSent = true;
|
|
|
|
|
|
|
|
if (this.userAlreadyActivated) {
|
|
|
|
await changeIdentity(this.$apollo.provider.defaultClient, data.registerPerson);
|
2019-01-30 15:54:21 +01:00
|
|
|
|
2019-10-04 18:28:25 +02:00
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
|
|
|
}
|
2019-01-30 15:54:21 +01:00
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
} catch (error) {
|
2019-01-29 11:02:32 +01:00
|
|
|
this.errors = error.graphQLErrors.reduce((acc, error) => {
|
|
|
|
acc[error.details] = error.message;
|
|
|
|
return acc;
|
2019-03-22 10:57:14 +01:00
|
|
|
}, {});
|
2019-01-21 15:08:22 +01:00
|
|
|
console.error(error);
|
2019-01-29 11:02:32 +01:00
|
|
|
console.error(this.errors);
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2019-10-10 14:20:09 +02:00
|
|
|
<style lang="scss" scoped>
|
2019-01-21 15:08:22 +01:00
|
|
|
.avatar-enter-active {
|
|
|
|
transition: opacity 1s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.avatar-enter,
|
|
|
|
.avatar-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.avatar-leave {
|
|
|
|
display: none;
|
|
|
|
}
|
2019-10-10 14:20:09 +02:00
|
|
|
|
|
|
|
.container .columns {
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
</style>
|