Handle validated users without profiles
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Format Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
640bb878e8
commit
1b470f3f04
@ -15,6 +15,10 @@ mutation ValidateUser($token: String!) {
|
||||
token,
|
||||
user {
|
||||
id,
|
||||
email,
|
||||
defaultActor {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,4 +37,4 @@ export const UPDATE_CURRENT_USER_CLIENT = gql`
|
||||
mutation UpdateCurrentUser($id: Int!, $email: String!) {
|
||||
updateCurrentUser(id: $id, email: $email) @client
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
@ -46,7 +46,8 @@ export default [
|
||||
path: '/validate/:token',
|
||||
name: 'Validate',
|
||||
component: Validate,
|
||||
props: true,
|
||||
// We can only pass string values through params, therefore
|
||||
props: (route) => ({ email: route.params.email, userAlreadyActivated: route.params.userAlreadyActivated === 'true'}),
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
{
|
||||
|
@ -57,7 +57,7 @@
|
||||
</b-field>
|
||||
</form>
|
||||
|
||||
<div v-if="validationSent">
|
||||
<div v-if="validationSent && !userAlreadyActivated">
|
||||
<b-message title="Success" type="is-success">
|
||||
<h2 class="title">
|
||||
<translate
|
||||
@ -92,8 +92,9 @@ import { MOBILIZON_INSTANCE_HOST } from "@/api/_entrypoint";
|
||||
}
|
||||
})
|
||||
export default class Register extends Vue {
|
||||
@Prop({ type: String, required: true })
|
||||
email!: string;
|
||||
@Prop({ type: String, required: true }) email!: string;
|
||||
@Prop({ type: Boolean, required: false, default: false }) userAlreadyActivated!: boolean;
|
||||
|
||||
host: string = MOBILIZON_INSTANCE_HOST;
|
||||
|
||||
person: IPerson = {
|
||||
@ -121,6 +122,10 @@ export default class Register extends Vue {
|
||||
variables: Object.assign({ email: this.email }, this.person)
|
||||
});
|
||||
this.validationSent = true;
|
||||
|
||||
if (this.userAlreadyActivated) {
|
||||
this.$router.push({name: "Home"});
|
||||
}
|
||||
} catch (error) {
|
||||
this.errors = error.graphQLErrors.reduce((acc, error) => {
|
||||
acc[error.details] = error.message;
|
||||
|
@ -5,8 +5,8 @@
|
||||
</h1>
|
||||
<div v-else>
|
||||
<div v-if="failed">
|
||||
<b-message title="Error" type="is-danger">
|
||||
<translate>Error while validating account</translate>
|
||||
<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>
|
||||
</b-message>
|
||||
</div>
|
||||
<h1 class="title" v-else>
|
||||
@ -28,21 +28,28 @@ export default class Validate extends Vue {
|
||||
loading = true;
|
||||
failed = false;
|
||||
|
||||
created() {
|
||||
this.validateAction();
|
||||
async created() {
|
||||
await this.validateAction();
|
||||
}
|
||||
|
||||
async validateAction() {
|
||||
try {
|
||||
const data = await this.$apollo.mutate({
|
||||
const { data } = await this.$apollo.mutate({
|
||||
mutation: VALIDATE_USER,
|
||||
variables: {
|
||||
token: this.token
|
||||
}
|
||||
});
|
||||
|
||||
this.saveUserData(data.data);
|
||||
this.saveUserData(data);
|
||||
|
||||
const user = data.validateUser.user;
|
||||
console.log(user);
|
||||
if (user.defaultActor) {
|
||||
this.$router.push({name: "Home"});
|
||||
} else { // If the user didn't register any profile yet, let's create one for them
|
||||
this.$router.push({ name: 'RegisterProfile', params: {email: user.email, userAlreadyActivated: 'true'} });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
this.failed = true;
|
||||
|
@ -77,8 +77,12 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
else
|
||||
{:error, :user_not_found} ->
|
||||
{:error, "User with email not found"}
|
||||
|
||||
{:no_actor, _} ->
|
||||
{:error, "You already have a profile for this user"}
|
||||
|
||||
{:error, %Ecto.Changeset{} = e} ->
|
||||
{:error, e}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -63,7 +63,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||
{:get_actor, actor} <- {:get_actor, Actors.get_actor_for_user(user)},
|
||||
{:guardian_encode_and_sign, {:ok, token, _}} <-
|
||||
{:guardian_encode_and_sign, MobilizonWeb.Guardian.encode_and_sign(user)} do
|
||||
{:ok, %{token: token, user: user, person: actor}}
|
||||
{:ok, %{token: token, user: Map.put(user, :default_actor, actor)}}
|
||||
else
|
||||
err ->
|
||||
Logger.info("Unable to validate user with token #{token}")
|
||||
|
Loading…
Reference in New Issue
Block a user