forked from potsda.mn/mobilizon
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
681653e035
commit
ce65c992d3
|
@ -15,6 +15,10 @@ mutation ValidateUser($token: String!) {
|
||||||
token,
|
token,
|
||||||
user {
|
user {
|
||||||
id,
|
id,
|
||||||
|
email,
|
||||||
|
defaultActor {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,4 +37,4 @@ export const UPDATE_CURRENT_USER_CLIENT = gql`
|
||||||
mutation UpdateCurrentUser($id: Int!, $email: String!) {
|
mutation UpdateCurrentUser($id: Int!, $email: String!) {
|
||||||
updateCurrentUser(id: $id, email: $email) @client
|
updateCurrentUser(id: $id, email: $email) @client
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
|
@ -46,7 +46,8 @@ export default [
|
||||||
path: '/validate/:token',
|
path: '/validate/:token',
|
||||||
name: 'Validate',
|
name: 'Validate',
|
||||||
component: 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 },
|
meta: { requiresAuth: false },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</b-field>
|
</b-field>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div v-if="validationSent">
|
<div v-if="validationSent && !userAlreadyActivated">
|
||||||
<b-message title="Success" type="is-success">
|
<b-message title="Success" type="is-success">
|
||||||
<h2 class="title">
|
<h2 class="title">
|
||||||
<translate
|
<translate
|
||||||
|
@ -92,8 +92,9 @@ import { MOBILIZON_INSTANCE_HOST } from "@/api/_entrypoint";
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default class Register extends Vue {
|
export default class Register extends Vue {
|
||||||
@Prop({ type: String, required: true })
|
@Prop({ type: String, required: true }) email!: string;
|
||||||
email!: string;
|
@Prop({ type: Boolean, required: false, default: false }) userAlreadyActivated!: boolean;
|
||||||
|
|
||||||
host: string = MOBILIZON_INSTANCE_HOST;
|
host: string = MOBILIZON_INSTANCE_HOST;
|
||||||
|
|
||||||
person: IPerson = {
|
person: IPerson = {
|
||||||
|
@ -121,6 +122,10 @@ export default class Register extends Vue {
|
||||||
variables: Object.assign({ email: this.email }, this.person)
|
variables: Object.assign({ email: this.email }, this.person)
|
||||||
});
|
});
|
||||||
this.validationSent = true;
|
this.validationSent = true;
|
||||||
|
|
||||||
|
if (this.userAlreadyActivated) {
|
||||||
|
this.$router.push({name: "Home"});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.errors = error.graphQLErrors.reduce((acc, error) => {
|
this.errors = error.graphQLErrors.reduce((acc, error) => {
|
||||||
acc[error.details] = error.message;
|
acc[error.details] = error.message;
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
</h1>
|
</h1>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div v-if="failed">
|
<div v-if="failed">
|
||||||
<b-message title="Error" type="is-danger">
|
<b-message :title="$gettext('Error while validating account')" type="is-danger">
|
||||||
<translate>Error while validating account</translate>
|
<translate>Either the account is already validated, either the validation token is incorrect.</translate>
|
||||||
</b-message>
|
</b-message>
|
||||||
</div>
|
</div>
|
||||||
<h1 class="title" v-else>
|
<h1 class="title" v-else>
|
||||||
|
@ -28,21 +28,28 @@ export default class Validate extends Vue {
|
||||||
loading = true;
|
loading = true;
|
||||||
failed = false;
|
failed = false;
|
||||||
|
|
||||||
created() {
|
async created() {
|
||||||
this.validateAction();
|
await this.validateAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateAction() {
|
async validateAction() {
|
||||||
try {
|
try {
|
||||||
const data = await this.$apollo.mutate({
|
const { data } = await this.$apollo.mutate({
|
||||||
mutation: VALIDATE_USER,
|
mutation: VALIDATE_USER,
|
||||||
variables: {
|
variables: {
|
||||||
token: this.token
|
token: this.token
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.saveUserData(data.data);
|
this.saveUserData(data);
|
||||||
this.$router.push({ name: "Home" });
|
|
||||||
|
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) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
this.failed = true;
|
this.failed = true;
|
||||||
|
|
|
@ -77,8 +77,12 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||||
else
|
else
|
||||||
{:error, :user_not_found} ->
|
{:error, :user_not_found} ->
|
||||||
{:error, "User with email not found"}
|
{:error, "User with email not found"}
|
||||||
|
|
||||||
{:no_actor, _} ->
|
{:no_actor, _} ->
|
||||||
{:error, "You already have a profile for this user"}
|
{:error, "You already have a profile for this user"}
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = e} ->
|
||||||
|
{:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
{:get_actor, actor} <- {:get_actor, Actors.get_actor_for_user(user)},
|
{:get_actor, actor} <- {:get_actor, Actors.get_actor_for_user(user)},
|
||||||
{:guardian_encode_and_sign, {:ok, token, _}} <-
|
{:guardian_encode_and_sign, {:ok, token, _}} <-
|
||||||
{:guardian_encode_and_sign, MobilizonWeb.Guardian.encode_and_sign(user)} do
|
{: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
|
else
|
||||||
err ->
|
err ->
|
||||||
Logger.info("Unable to validate user with token #{token}")
|
Logger.info("Unable to validate user with token #{token}")
|
||||||
|
|
Loading…
Reference in a new issue