Fix user registration and validation
This commit is contained in:
parent
649bc5624d
commit
d8dde92c86
|
@ -121,12 +121,9 @@
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
rules = {
|
rules = {
|
||||||
password_length: value => value.length > 6 || 'Password must be at least 6 caracters long',
|
password_length: value => value.length > 6 || 'Password must be at least 6 characters long',
|
||||||
required: value => !!value || 'Required.',
|
required: value => !!value || 'Required.',
|
||||||
email: (value) => {
|
email: (value: string) => value.indexOf('@') !== -1 || 'Invalid e-mail.',
|
||||||
const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
||||||
return pattern.test(value) || 'Invalid e-mail.';
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
resetState() {
|
resetState() {
|
||||||
|
@ -154,20 +151,21 @@
|
||||||
return this.rules.email(this.email) === true ? 'v-gravatar' : 'avatar';
|
return this.rules.email(this.email) === true ? 'v-gravatar' : 'avatar';
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
async submit() {
|
||||||
this.$apollo.mutate({
|
try {
|
||||||
|
await this.$apollo.mutate({
|
||||||
mutation: CREATE_USER,
|
mutation: CREATE_USER,
|
||||||
variables: {
|
variables: {
|
||||||
email: this.email,
|
email: this.email,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
},
|
},
|
||||||
}).then((data) => {
|
|
||||||
console.log(data);
|
|
||||||
this.validationSent = true;
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.validationSent = true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { VALIDATE_USER } from '@/graphql/user';
|
import { VALIDATE_USER } from '@/graphql/user';
|
||||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
import { AUTH_TOKEN, AUTH_USER_ACTOR, AUTH_USER_ID } from '@/constants';
|
import { AUTH_TOKEN, AUTH_USER_ID } from '@/constants';
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class Validate extends Vue {
|
export default class Validate extends Vue {
|
||||||
|
@ -32,27 +32,27 @@
|
||||||
this.validateAction();
|
this.validateAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
validateAction() {
|
async validateAction() {
|
||||||
this.$apollo.mutate({
|
try {
|
||||||
|
const data = await this.$apollo.mutate({
|
||||||
mutation: VALIDATE_USER,
|
mutation: VALIDATE_USER,
|
||||||
variables: {
|
variables: {
|
||||||
token: this.token,
|
token: this.token,
|
||||||
},
|
},
|
||||||
}).then((data) => {
|
});
|
||||||
this.loading = false;
|
|
||||||
console.log(data);
|
|
||||||
this.saveUserData(data.data);
|
this.saveUserData(data.data);
|
||||||
this.$router.push({ name: 'Home' });
|
this.$router.push({ name: 'Home' });
|
||||||
}).catch((error) => {
|
} catch (err) {
|
||||||
this.loading = false;
|
console.error(err);
|
||||||
console.log(error);
|
|
||||||
this.failed = true;
|
this.failed = true;
|
||||||
});
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveUserData({ validateUser: login }) {
|
saveUserData({ validateUser: login }) {
|
||||||
localStorage.setItem(AUTH_USER_ID, login.user.id);
|
localStorage.setItem(AUTH_USER_ID, login.user.id);
|
||||||
localStorage.setItem(AUTH_USER_ACTOR, JSON.stringify(login.actor));
|
|
||||||
localStorage.setItem(AUTH_TOKEN, login.token);
|
localStorage.setItem(AUTH_TOKEN, login.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,10 @@ import gql from 'graphql-tag';
|
||||||
export const CREATE_USER = gql`
|
export const CREATE_USER = gql`
|
||||||
mutation CreateUser($email: String!, $username: String!, $password: String!) {
|
mutation CreateUser($email: String!, $username: String!, $password: String!) {
|
||||||
createUser(email: $email, username: $username, password: $password) {
|
createUser(email: $email, username: $username, password: $password) {
|
||||||
preferredUsername,
|
|
||||||
user {
|
|
||||||
email,
|
email,
|
||||||
confirmationSentAt
|
confirmationSentAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const VALIDATE_USER = gql`
|
export const VALIDATE_USER = gql`
|
||||||
|
@ -18,10 +15,6 @@ mutation ValidateUser($token: String!) {
|
||||||
token,
|
token,
|
||||||
user {
|
user {
|
||||||
id,
|
id,
|
||||||
},
|
|
||||||
actor {
|
|
||||||
avatarUrl,
|
|
||||||
preferredUsername,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,13 @@ defmodule Mobilizon.Actors do
|
||||||
"""
|
"""
|
||||||
@spec get_actor_for_user(Mobilizon.Actors.User.t()) :: Mobilizon.Actors.Actor.t()
|
@spec get_actor_for_user(Mobilizon.Actors.User.t()) :: Mobilizon.Actors.Actor.t()
|
||||||
def get_actor_for_user(%Mobilizon.Actors.User{} = user) do
|
def get_actor_for_user(%Mobilizon.Actors.User{} = user) do
|
||||||
case Repo.one(from(a in Actor, join: u in User, on: u.default_actor_id == a.id)) do
|
case Repo.one(
|
||||||
|
from(a in Actor,
|
||||||
|
join: u in User,
|
||||||
|
on: u.default_actor_id == a.id,
|
||||||
|
where: u.id == ^user.id
|
||||||
|
)
|
||||||
|
) do
|
||||||
nil -> get_actors_for_user(user) |> hd
|
nil -> get_actors_for_user(user) |> hd
|
||||||
actor -> actor
|
actor -> actor
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue