2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<section class="container mx-auto">
|
|
|
|
<div class="">
|
|
|
|
<div class="">
|
|
|
|
<h1 class="text-2xl" v-if="userAlreadyActivated">
|
2020-10-06 09:54:07 +02:00
|
|
|
{{ $t("Congratulations, your account is now created!") }}
|
|
|
|
</h1>
|
2022-07-12 10:55:28 +02:00
|
|
|
<h1 class="text-2xl" v-else>
|
2020-11-30 10:24:11 +01:00
|
|
|
{{
|
|
|
|
$t("Register an account on {instanceName}!", {
|
2022-07-12 10:55:28 +02:00
|
|
|
instanceName,
|
2020-11-30 10:24:11 +01:00
|
|
|
})
|
|
|
|
}}
|
2020-11-17 10:57:04 +01:00
|
|
|
</h1>
|
2022-07-12 10:55:28 +02:00
|
|
|
<p class="prose dark:prose-invert" v-if="userAlreadyActivated">
|
2020-10-06 09:54:07 +02:00
|
|
|
{{ $t("Now, create your first profile:") }}
|
|
|
|
</p>
|
2019-10-12 13:16:36 +02:00
|
|
|
<form v-if="!validationSent" @submit.prevent="submit">
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-field :label="$t('Displayed nickname')">
|
|
|
|
<o-input
|
2020-02-18 08:57:00 +01:00
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
v-model="identity.name"
|
2022-07-12 10:55:28 +02:00
|
|
|
@input="autoUpdateUsername"
|
2020-02-18 08:57:00 +01:00
|
|
|
/>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-field>
|
2019-11-18 17:37:38 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-field
|
2019-10-10 14:20:09 +02:00
|
|
|
:label="$t('Username')"
|
|
|
|
:type="errors.preferred_username ? 'is-danger' : null"
|
|
|
|
:message="errors.preferred_username"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-field
|
2020-11-17 19:14:55 +01:00
|
|
|
:message="
|
2020-11-30 10:24:11 +01:00
|
|
|
$t(
|
|
|
|
'Only alphanumeric lowercased characters and underscores are supported.'
|
|
|
|
)
|
2020-11-17 19:14:55 +01:00
|
|
|
"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-input
|
2019-10-10 14:20:09 +02:00
|
|
|
aria-required="true"
|
|
|
|
required
|
|
|
|
expanded
|
2019-11-18 17:37:38 +01:00
|
|
|
v-model="identity.preferredUsername"
|
2020-11-17 19:14:55 +01:00
|
|
|
:validation-message="
|
|
|
|
identity.preferredUsername
|
2020-11-30 10:24:11 +01:00
|
|
|
? $t(
|
|
|
|
'Only alphanumeric lowercased characters and underscores are supported.'
|
|
|
|
)
|
2020-11-17 19:14:55 +01:00
|
|
|
: null
|
|
|
|
"
|
2019-10-10 14:20:09 +02:00
|
|
|
/>
|
|
|
|
<p class="control">
|
|
|
|
<span class="button is-static">@{{ host }}</span>
|
|
|
|
</p>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-field>
|
|
|
|
</o-field>
|
2020-08-31 12:40:30 +02:00
|
|
|
<p class="description">
|
2020-11-30 10:24:11 +01:00
|
|
|
{{
|
|
|
|
$t(
|
|
|
|
"This identifier is unique to your profile. It allows others to find you."
|
|
|
|
)
|
|
|
|
}}
|
2020-08-31 12:40:30 +02:00
|
|
|
</p>
|
2019-10-10 14:20:09 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-field :label="$t('Short bio')">
|
|
|
|
<o-input
|
2020-11-30 10:24:11 +01:00
|
|
|
type="textarea"
|
|
|
|
maxlength="100"
|
|
|
|
rows="2"
|
|
|
|
v-model="identity.summary"
|
|
|
|
/>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-field>
|
2019-10-10 14:20:09 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<p class="prose dark:prose-invert">
|
2020-10-06 15:36:19 +02:00
|
|
|
{{
|
|
|
|
$t(
|
|
|
|
"You will be able to add an avatar and set other options in your account settings."
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</p>
|
|
|
|
|
2019-10-10 14:20:09 +02:00
|
|
|
<p class="control has-text-centered">
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-button
|
|
|
|
variant="primary"
|
|
|
|
size="large"
|
2020-06-15 11:01:49 +02:00
|
|
|
native-type="submit"
|
|
|
|
:disabled="sendingValidation"
|
2022-07-12 10:55:28 +02:00
|
|
|
>{{ $t("Create my profile") }}</o-button
|
2020-06-15 11:01:49 +02:00
|
|
|
>
|
2019-10-10 14:20:09 +02:00
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<div v-if="validationSent && !userAlreadyActivated">
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-notification variant="success" :closable="false">
|
2019-10-10 14:20:09 +02:00
|
|
|
<h2 class="title">
|
2020-02-18 08:57:00 +01:00
|
|
|
{{
|
|
|
|
$t("Your account is nearly ready, {username}", {
|
2022-07-12 10:55:28 +02:00
|
|
|
username: identity.name ?? identity.preferredUsername,
|
2020-02-18 08:57:00 +01:00
|
|
|
})
|
|
|
|
}}
|
2019-10-10 14:20:09 +02:00
|
|
|
</h2>
|
2022-07-12 10:55:28 +02:00
|
|
|
<i18n-t keypath="A validation email was sent to {email}" tag="p">
|
|
|
|
<template #email>
|
|
|
|
<code>{{ email }}</code>
|
|
|
|
</template>
|
|
|
|
</i18n-t>
|
2019-10-10 14:20:09 +02:00
|
|
|
<p>
|
2020-02-18 08:57:00 +01:00
|
|
|
{{
|
|
|
|
$t(
|
2020-06-15 11:01:49 +02:00
|
|
|
"Before you can login, you need to click on the link inside it to validate your account."
|
2020-02-18 08:57:00 +01:00
|
|
|
)
|
|
|
|
}}
|
2019-10-10 14:20:09 +02:00
|
|
|
</p>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-notification>
|
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>
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { Person } from "../../types/actor";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { MOBILIZON_INSTANCE_HOST } from "../../api/_entrypoint";
|
|
|
|
import RouteName from "../../router/name";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { changeIdentity } from "../../utils/identity";
|
|
|
|
import { useInstanceName } from "@/composition/apollo/config";
|
|
|
|
import { ref, computed, onBeforeMount } from "vue";
|
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
import { registerAccount } from "@/composition/apollo/user";
|
|
|
|
import { convertToUsername } from "@/utils/username";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import { useHead } from "@vueuse/head";
|
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
email: string;
|
|
|
|
userAlreadyActivated?: boolean;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
userAlreadyActivated: false,
|
|
|
|
}
|
|
|
|
);
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { instanceName } = useInstanceName();
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const router = useRouter();
|
2019-01-30 15:54:21 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2020-11-17 10:57:04 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
useHead({
|
|
|
|
title: computed(() => t("Register")),
|
|
|
|
});
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const host: string = MOBILIZON_INSTANCE_HOST;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const errors = ref<Record<string, unknown>>({});
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const validationSent = ref(false);
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const sendingValidation = ref(false);
|
|
|
|
|
|
|
|
const identity = ref(new Person());
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
// Make sure no one goes to this page if we don't want to
|
|
|
|
if (!props.email) {
|
|
|
|
router.replace({ name: RouteName.PAGE_NOT_FOUND });
|
2019-10-04 18:33:38 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2019-10-04 18:33:38 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const autoUpdateUsername = () => {
|
|
|
|
identity.value.preferredUsername = convertToUsername(identity.value.name);
|
|
|
|
};
|
2019-10-04 18:28:25 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const submit = async (): Promise<void> => {
|
|
|
|
sendingValidation.value = true;
|
|
|
|
errors.value = {};
|
|
|
|
const { onDone, onError } = registerAccount(
|
|
|
|
{ email: props.email, ...identity.value },
|
|
|
|
props.userAlreadyActivated
|
|
|
|
);
|
2021-08-03 14:58:42 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
onDone(async ({ data }) => {
|
|
|
|
validationSent.value = true;
|
|
|
|
window.localStorage.setItem("new-registered-user", "yes");
|
2019-10-04 18:28:25 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
if (data && props.userAlreadyActivated) {
|
|
|
|
await changeIdentity(data.registerPerson);
|
2019-01-30 15:54:21 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
await router.push({ name: RouteName.HOME });
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
onError((err) => {
|
|
|
|
errors.value = err.graphQLErrors.reduce(
|
|
|
|
(acc: { [key: string]: string }, error: any) => {
|
|
|
|
acc[error.details || error.field] = error.message;
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
console.error("Error while registering person", err);
|
|
|
|
console.error("Errors while registering person", errors);
|
|
|
|
sendingValidation.value = false;
|
|
|
|
});
|
|
|
|
};
|
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
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.container .columns {
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
}
|
2020-08-31 12:40:30 +02:00
|
|
|
|
|
|
|
p.description {
|
|
|
|
font-size: 0.9rem;
|
2020-10-06 09:54:07 +02:00
|
|
|
margin-bottom: 15px;
|
|
|
|
margin-top: -10px;
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
</style>
|