Introduce registerPerson mutation
To register a profile from an unactivated user
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
👤 Fix Person interface use
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Change host function for data property
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
c55ae19f84
commit
681653e035
|
@ -39,10 +39,34 @@ query {
|
||||||
|
|
||||||
export const CREATE_PERSON = gql`
|
export const CREATE_PERSON = gql`
|
||||||
mutation CreatePerson($preferredUsername: String!) {
|
mutation CreatePerson($preferredUsername: String!) {
|
||||||
createPerson(preferredUsername: $preferredUsername) {
|
createPerson(
|
||||||
|
preferredUsername: $preferredUsername,
|
||||||
|
name: $name,
|
||||||
|
summary: $summary
|
||||||
|
) {
|
||||||
preferredUsername,
|
preferredUsername,
|
||||||
name,
|
name,
|
||||||
|
summary,
|
||||||
avatarUrl
|
avatarUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This one is used only to register the first account. Prefer CREATE_PERSON when creating another identity
|
||||||
|
*/
|
||||||
|
export const REGISTER_PERSON = gql`
|
||||||
|
mutation ($preferredUsername: String!, $name: String!, $summary: String!, $email: String!) {
|
||||||
|
registerPerson(
|
||||||
|
preferredUsername: $preferredUsername,
|
||||||
|
name: $name,
|
||||||
|
summary: $summary,
|
||||||
|
email: $email
|
||||||
|
) {
|
||||||
|
preferredUsername,
|
||||||
|
name,
|
||||||
|
summary,
|
||||||
|
avatarUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import gql from 'graphql-tag';
|
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!, $password: String!) {
|
||||||
createUser(email: $email, username: $username, password: $password) {
|
createUser(email: $email, password: $password) {
|
||||||
email,
|
email,
|
||||||
confirmationSentAt
|
confirmationSentAt
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,17 +8,12 @@ import Location from '@/views/Location.vue';
|
||||||
import CreateEvent from '@/views/Event/Create.vue';
|
import CreateEvent from '@/views/Event/Create.vue';
|
||||||
import CategoryList from '@/views/Category/List.vue';
|
import CategoryList from '@/views/Category/List.vue';
|
||||||
import CreateCategory from '@/views/Category/Create.vue';
|
import CreateCategory from '@/views/Category/Create.vue';
|
||||||
import Register from '@/views/Account/Register.vue';
|
|
||||||
import Login from '@/views/User/Login.vue';
|
|
||||||
import Validate from '@/views/User/Validate.vue';
|
|
||||||
import ResendConfirmation from '@/views/User/ResendConfirmation.vue';
|
|
||||||
import SendPasswordReset from '@/views/User/SendPasswordReset.vue';
|
|
||||||
import PasswordReset from '@/views/User/PasswordReset.vue';
|
|
||||||
import Profile from '@/views/Account/Profile.vue';
|
import Profile from '@/views/Account/Profile.vue';
|
||||||
import CreateGroup from '@/views/Group/Create.vue';
|
import CreateGroup from '@/views/Group/Create.vue';
|
||||||
import Group from '@/views/Group/Group.vue';
|
import Group from '@/views/Group/Group.vue';
|
||||||
import GroupList from '@/views/Group/GroupList.vue';
|
import GroupList from '@/views/Group/GroupList.vue';
|
||||||
import Identities from '@/views/Account/Identities.vue';
|
import Identities from '@/views/Account/Identities.vue';
|
||||||
|
import userRoutes from './user';
|
||||||
|
|
||||||
Vue.use(Router);
|
Vue.use(Router);
|
||||||
|
|
||||||
|
@ -26,6 +21,7 @@ const router = new Router({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: '/',
|
base: '/',
|
||||||
routes: [
|
routes: [
|
||||||
|
...userRoutes,
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
|
@ -69,48 +65,6 @@ const router = new Router({
|
||||||
component: CreateCategory,
|
component: CreateCategory,
|
||||||
meta: { requiredAuth: true },
|
meta: { requiredAuth: true },
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/register',
|
|
||||||
name: 'Register',
|
|
||||||
component: Register,
|
|
||||||
props: true,
|
|
||||||
meta: { requiredAuth: false },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/resend-instructions',
|
|
||||||
name: 'ResendConfirmation',
|
|
||||||
component: ResendConfirmation,
|
|
||||||
props: true,
|
|
||||||
meta: { requiresAuth: false },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/password-reset/send',
|
|
||||||
name: 'SendPasswordReset',
|
|
||||||
component: SendPasswordReset,
|
|
||||||
props: true,
|
|
||||||
meta: { requiresAuth: false },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/password-reset/:token',
|
|
||||||
name: 'PasswordReset',
|
|
||||||
component: PasswordReset,
|
|
||||||
meta: { requiresAuth: false },
|
|
||||||
props: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/validate/:token',
|
|
||||||
name: 'Validate',
|
|
||||||
component: Validate,
|
|
||||||
props: true,
|
|
||||||
meta: { requiresAuth: false },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/login',
|
|
||||||
name: 'Login',
|
|
||||||
component: Login,
|
|
||||||
props: true,
|
|
||||||
meta: { requiredAuth: false },
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/identities',
|
path: '/identities',
|
||||||
name: 'Identities',
|
name: 'Identities',
|
||||||
|
|
59
js/src/router/user.ts
Normal file
59
js/src/router/user.ts
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
import RegisterUser from '@/views/User/Register.vue';
|
||||||
|
import RegisterProfile from '@/views/Account/Register.vue';
|
||||||
|
import Login from '@/views/User/Login.vue';
|
||||||
|
import Validate from '@/views/User/Validate.vue';
|
||||||
|
import ResendConfirmation from '@/views/User/ResendConfirmation.vue';
|
||||||
|
import SendPasswordReset from '@/views/User/SendPasswordReset.vue';
|
||||||
|
import PasswordReset from '@/views/User/PasswordReset.vue';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
path: '/register/user',
|
||||||
|
name: 'Register',
|
||||||
|
component: RegisterUser,
|
||||||
|
props: true,
|
||||||
|
meta: { requiredAuth: false },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/register/profile',
|
||||||
|
name: 'RegisterProfile',
|
||||||
|
component: RegisterProfile,
|
||||||
|
props: true,
|
||||||
|
meta: { requiredAuth: false },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/resend-instructions',
|
||||||
|
name: 'ResendConfirmation',
|
||||||
|
component: ResendConfirmation,
|
||||||
|
props: true,
|
||||||
|
meta: { requiresAuth: false },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/password-reset/send',
|
||||||
|
name: 'SendPasswordReset',
|
||||||
|
component: SendPasswordReset,
|
||||||
|
props: true,
|
||||||
|
meta: { requiresAuth: false },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/password-reset/:token',
|
||||||
|
name: 'PasswordReset',
|
||||||
|
component: PasswordReset,
|
||||||
|
meta: { requiresAuth: false },
|
||||||
|
props: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/validate/:token',
|
||||||
|
name: 'Validate',
|
||||||
|
component: Validate,
|
||||||
|
props: true,
|
||||||
|
meta: { requiresAuth: false },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
name: 'Login',
|
||||||
|
component: Login,
|
||||||
|
props: true,
|
||||||
|
meta: { requiredAuth: false },
|
||||||
|
},
|
||||||
|
];
|
|
@ -2,7 +2,7 @@ export interface IActor {
|
||||||
id: string;
|
id: string;
|
||||||
url: string;
|
url: string;
|
||||||
name: string;
|
name: string;
|
||||||
domain: string;
|
domain: string|null;
|
||||||
summary: string;
|
summary: string;
|
||||||
preferredUsername: string;
|
preferredUsername: string;
|
||||||
suspended: boolean;
|
suspended: boolean;
|
||||||
|
|
|
@ -10,102 +10,63 @@
|
||||||
<section>
|
<section>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="columns is-mobile">
|
<div class="columns is-mobile">
|
||||||
<div class="column">
|
|
||||||
<div class="content">
|
|
||||||
<h2 class="subtitle" v-translate>Features</h2>
|
|
||||||
<ul>
|
|
||||||
<li v-translate>Create your communities and your events</li>
|
|
||||||
<li v-translate>Other stuff…</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<p v-translate>
|
|
||||||
Learn more on
|
|
||||||
<a target="_blank" href="https://joinmobilizon.org">joinmobilizon.org</a>
|
|
||||||
</p>
|
|
||||||
<hr>
|
|
||||||
<div class="content">
|
|
||||||
<h2 class="subtitle" v-translate>About this instance</h2>
|
|
||||||
<p>
|
|
||||||
<translate>Your local administrator resumed it's policy:</translate>
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li v-translate>Please be nice to each other</li>
|
|
||||||
<li v-translate>meditate a bit</li>
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
<translate>Please read the full rules</translate>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<form v-if="!validationSent">
|
<form v-if="!validationSent">
|
||||||
<div class="columns is-mobile is-centered">
|
<div class="columns is-mobile is-centered">
|
||||||
<div class="column is-narrow">
|
<div class="column is-narrow">
|
||||||
<figure class="image is-64x64">
|
<figure class="image is-64x64">
|
||||||
<transition name="avatar">
|
<transition name="avatar">
|
||||||
<v-gravatar v-bind="{email: credentials.email}" default-img="mp"></v-gravatar>
|
<v-gravatar v-bind="{email: email}" default-img="mp"></v-gravatar>
|
||||||
</transition>
|
</transition>
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<b-field label="Email">
|
<b-field
|
||||||
|
:label="$gettext('Username')"
|
||||||
|
:type="errors.preferred_username ? 'is-danger' : null"
|
||||||
|
:message="errors.preferred_username"
|
||||||
|
>
|
||||||
|
<b-field>
|
||||||
<b-input
|
<b-input
|
||||||
aria-required="true"
|
aria-required="true"
|
||||||
required
|
required
|
||||||
type="email"
|
expanded
|
||||||
v-model="credentials.email"
|
v-model="person.preferredUsername"
|
||||||
@blur="showGravatar = true"
|
|
||||||
@focus="showGravatar = false"
|
|
||||||
/>
|
/>
|
||||||
|
<p class="control">
|
||||||
|
<span class="button is-static">@{{ host }}</span>
|
||||||
|
</p>
|
||||||
|
</b-field>
|
||||||
</b-field>
|
</b-field>
|
||||||
|
|
||||||
<b-field label="Username">
|
<b-field :label="$gettext('Displayed name')">
|
||||||
<b-input aria-required="true" required v-model="credentials.username"/>
|
<b-input v-model="person.name"/>
|
||||||
</b-field>
|
</b-field>
|
||||||
|
|
||||||
<b-field label="Password">
|
<b-field :label="$gettext('Description')">
|
||||||
<b-input
|
<b-input type="textarea" v-model="person.summary"/>
|
||||||
aria-required="true"
|
|
||||||
required
|
|
||||||
type="password"
|
|
||||||
password-reveal
|
|
||||||
minlength="6"
|
|
||||||
v-model="credentials.password"
|
|
||||||
/>
|
|
||||||
</b-field>
|
</b-field>
|
||||||
|
|
||||||
<b-field grouped>
|
<b-field grouped>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button type="button" class="button is-primary" @click="submit()">
|
<button type="button" class="button is-primary" @click="submit()">
|
||||||
<translate>Register</translate>
|
<translate>Create my profile</translate>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
|
||||||
<router-link
|
|
||||||
class="button is-text"
|
|
||||||
:to="{ name: 'ResendConfirmation', params: { email: credentials.email }}"
|
|
||||||
>
|
|
||||||
<translate>Didn't receive the instructions ?</translate>
|
|
||||||
</router-link>
|
|
||||||
</div>
|
|
||||||
<div class="control">
|
|
||||||
<router-link
|
|
||||||
class="button is-text"
|
|
||||||
:to="{ name: 'Login', params: { email: credentials.email, password: credentials.password }}"
|
|
||||||
:disabled="validationSent"
|
|
||||||
>
|
|
||||||
<translate>Login</translate>
|
|
||||||
</router-link>
|
|
||||||
</div>
|
|
||||||
</b-field>
|
</b-field>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div v-if="validationSent">
|
<div v-if="validationSent">
|
||||||
<b-message title="Success" type="is-success">
|
<b-message title="Success" type="is-success">
|
||||||
<h2>
|
<h2 class="title">
|
||||||
<translate>A validation email was sent to %{email}</translate>
|
<translate
|
||||||
|
:translate-params="{ username: person.preferredUsername }"
|
||||||
|
>Your account is nearly ready, %{username}</translate>
|
||||||
</h2>
|
</h2>
|
||||||
|
<p>
|
||||||
|
<translate>A validation email was sent to %{email}</translate>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<translate>Before you can login, you need to click on the link inside it to validate your account</translate>
|
<translate>Before you can login, you need to click on the link inside it to validate your account</translate>
|
||||||
</p>
|
</p>
|
||||||
|
@ -120,8 +81,9 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Gravatar from "vue-gravatar";
|
import Gravatar from "vue-gravatar";
|
||||||
import { CREATE_USER } from "@/graphql/user";
|
|
||||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||||
|
import { IPerson } from "@/types/actor.model";
|
||||||
|
import { REGISTER_PERSON } from "@/graphql/actor";
|
||||||
import { MOBILIZON_INSTANCE_HOST } from "@/api/_entrypoint";
|
import { MOBILIZON_INSTANCE_HOST } from "@/api/_entrypoint";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -130,37 +92,42 @@ import { MOBILIZON_INSTANCE_HOST } from "@/api/_entrypoint";
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default class Register extends Vue {
|
export default class Register extends Vue {
|
||||||
@Prop({ type: String, required: false, default: "" }) email!: string;
|
@Prop({ type: String, required: true })
|
||||||
@Prop({ type: String, required: false, default: "" }) password!: string;
|
email!: string;
|
||||||
|
host: string = MOBILIZON_INSTANCE_HOST;
|
||||||
|
|
||||||
credentials = {
|
person: IPerson = {
|
||||||
username: "",
|
preferredUsername: "",
|
||||||
email: this.email,
|
name: "",
|
||||||
password: this.password
|
summary: "",
|
||||||
} as { username: string; email: string; password: string };
|
id: "",
|
||||||
errors: string[] = [];
|
url: "",
|
||||||
|
suspended: false,
|
||||||
|
avatarUrl: "", // TODO : Use Gravatar here
|
||||||
|
bannerUrl: "",
|
||||||
|
domain: null,
|
||||||
|
};
|
||||||
|
errors: object = {};
|
||||||
validationSent: boolean = false;
|
validationSent: boolean = false;
|
||||||
|
sendingValidation: boolean = false;
|
||||||
showGravatar: boolean = false;
|
showGravatar: boolean = false;
|
||||||
|
|
||||||
host() {
|
|
||||||
return MOBILIZON_INSTANCE_HOST;
|
|
||||||
}
|
|
||||||
|
|
||||||
validEmail() {
|
|
||||||
return this.credentials.email.includes("@") === true
|
|
||||||
? "v-gravatar"
|
|
||||||
: "avatar";
|
|
||||||
}
|
|
||||||
|
|
||||||
async submit() {
|
async submit() {
|
||||||
try {
|
try {
|
||||||
this.validationSent = true;
|
this.sendingValidation = true;
|
||||||
|
this.errors = {};
|
||||||
await this.$apollo.mutate({
|
await this.$apollo.mutate({
|
||||||
mutation: CREATE_USER,
|
mutation: REGISTER_PERSON,
|
||||||
variables: this.credentials
|
variables: Object.assign({ email: this.email }, this.person)
|
||||||
});
|
});
|
||||||
|
this.validationSent = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
this.errors = error.graphQLErrors.reduce((acc, error) => {
|
||||||
|
acc[error.details] = error.message;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
console.error(this.errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
177
js/src/views/User/Register.vue
Normal file
177
js/src/views/User/Register.vue
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<section class="hero">
|
||||||
|
<div class="hero-body">
|
||||||
|
<h1 class="title">
|
||||||
|
<translate>Register an account on Mobilizon!</translate>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<div class="container">
|
||||||
|
<div class="columns is-mobile">
|
||||||
|
<div class="column">
|
||||||
|
<div class="content">
|
||||||
|
<h2 class="subtitle" v-translate>Features</h2>
|
||||||
|
<ul>
|
||||||
|
<li v-translate>Create your communities and your events</li>
|
||||||
|
<li v-translate>Other stuff…</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<p v-translate>
|
||||||
|
Learn more on
|
||||||
|
<a target="_blank" href="https://joinmobilizon.org">joinmobilizon.org</a>
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
|
<div class="content">
|
||||||
|
<h2 class="subtitle" v-translate>About this instance</h2>
|
||||||
|
<p>
|
||||||
|
<translate>Your local administrator resumed it's policy:</translate>
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li v-translate>Please be nice to each other</li>
|
||||||
|
<li v-translate>meditate a bit</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
<translate>Please read the full rules</translate>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<form @submit="submit">
|
||||||
|
<b-field
|
||||||
|
label="Email"
|
||||||
|
:type="errors.email ? 'is-danger' : null"
|
||||||
|
:message="errors.email"
|
||||||
|
>
|
||||||
|
<b-input
|
||||||
|
aria-required="true"
|
||||||
|
required
|
||||||
|
type="email"
|
||||||
|
v-model="credentials.email"
|
||||||
|
@blur="showGravatar = true"
|
||||||
|
@focus="showGravatar = false"
|
||||||
|
/>
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field
|
||||||
|
label="Password"
|
||||||
|
:type="errors.password ? 'is-danger' : null"
|
||||||
|
:message="errors.password"
|
||||||
|
>
|
||||||
|
<b-input
|
||||||
|
aria-required="true"
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
password-reveal
|
||||||
|
minlength="6"
|
||||||
|
v-model="credentials.password"
|
||||||
|
/>
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field grouped>
|
||||||
|
<div class="control">
|
||||||
|
<button type="button" class="button is-primary" @click="submit()">
|
||||||
|
<translate>Register</translate>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<router-link
|
||||||
|
class="button is-text"
|
||||||
|
:to="{ name: 'ResendConfirmation', params: { email: credentials.email }}"
|
||||||
|
>
|
||||||
|
<translate>Didn't receive the instructions ?</translate>
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<router-link
|
||||||
|
class="button is-text"
|
||||||
|
:to="{ name: 'Login', params: { email: credentials.email, password: credentials.password }}"
|
||||||
|
:disabled="sendingValidation"
|
||||||
|
>
|
||||||
|
<translate>Login</translate>
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</b-field>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div v-if="errors.length > 0">
|
||||||
|
<b-message type="is-danger" v-for="error in errors" :key="error">
|
||||||
|
<translate>{{ error }}</translate>
|
||||||
|
</b-message>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import Gravatar from "vue-gravatar";
|
||||||
|
import { CREATE_USER } from "@/graphql/user";
|
||||||
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
components: {
|
||||||
|
"v-gravatar": Gravatar
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export default class Register extends Vue {
|
||||||
|
@Prop({ type: String, required: false, default: "" }) email!: string;
|
||||||
|
@Prop({ type: String, required: false, default: "" }) password!: string;
|
||||||
|
|
||||||
|
credentials = {
|
||||||
|
email: this.email,
|
||||||
|
password: this.password
|
||||||
|
} as { email: string; password: string };
|
||||||
|
errors: object = {};
|
||||||
|
sendingValidation: boolean = false;
|
||||||
|
validationSent: boolean = false;
|
||||||
|
showGravatar: boolean = false;
|
||||||
|
|
||||||
|
validEmail() {
|
||||||
|
return this.credentials.email.includes("@") === true
|
||||||
|
? "v-gravatar"
|
||||||
|
: "avatar";
|
||||||
|
}
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
try {
|
||||||
|
this.sendingValidation = true;
|
||||||
|
this.errors = {};
|
||||||
|
await this.$apollo.mutate({
|
||||||
|
mutation: CREATE_USER,
|
||||||
|
variables: this.credentials
|
||||||
|
});
|
||||||
|
this.validationSent = true;
|
||||||
|
this.$router.push({
|
||||||
|
name: "RegisterProfile",
|
||||||
|
params: { email: this.credentials.email }
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
this.errors = error.graphQLErrors.reduce((acc, error) => {
|
||||||
|
acc[error.details] = error.message;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
console.log(this.errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.avatar-enter-active {
|
||||||
|
transition: opacity 1s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-enter,
|
||||||
|
.avatar-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-leave {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -103,6 +103,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
:user_id
|
:user_id
|
||||||
])
|
])
|
||||||
|> build_urls()
|
|> build_urls()
|
||||||
|
# Needed because following constraint can't work for domain null values (local)
|
||||||
|
|> unique_username_validator()
|
||||||
|> unique_constraint(:preferred_username, name: :actors_preferred_username_domain_type_index)
|
|> unique_constraint(:preferred_username, name: :actors_preferred_username_domain_type_index)
|
||||||
|> unique_constraint(:url, name: :actors_url_index)
|
|> unique_constraint(:url, name: :actors_url_index)
|
||||||
|> validate_required([:preferred_username, :keys, :suspended, :url, :type])
|
|> validate_required([:preferred_username, :keys, :suspended, :url, :type])
|
||||||
|
@ -177,6 +179,16 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
|> put_change(:local, true)
|
|> put_change(:local, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unique_username_validator(
|
||||||
|
%Ecto.Changeset{changes: %{preferred_username: username}} = changeset
|
||||||
|
) do
|
||||||
|
if Actors.get_local_actor_by_name(username) do
|
||||||
|
changeset |> add_error(:preferred_username, "Username is already taken")
|
||||||
|
else
|
||||||
|
changeset
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
|
@spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
|
||||||
defp build_urls(changeset, type \\ :Person)
|
defp build_urls(changeset, type \\ :Person)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ defmodule Mobilizon.Actors.User do
|
||||||
|> cast(attrs, [
|
|> cast(attrs, [
|
||||||
:email,
|
:email,
|
||||||
:role,
|
:role,
|
||||||
|
:password,
|
||||||
:password_hash,
|
:password_hash,
|
||||||
:confirmed_at,
|
:confirmed_at,
|
||||||
:confirmation_sent_at,
|
:confirmation_sent_at,
|
||||||
|
@ -38,13 +39,13 @@ defmodule Mobilizon.Actors.User do
|
||||||
:reset_password_token
|
:reset_password_token
|
||||||
])
|
])
|
||||||
|> validate_required([:email])
|
|> validate_required([:email])
|
||||||
|> unique_constraint(:email, message: "registration.error.email_already_used")
|
|> unique_constraint(:email, message: "This email is already used.")
|
||||||
|> validate_format(:email, ~r/@/)
|
|> validate_email()
|
||||||
|> validate_length(
|
|> validate_length(
|
||||||
:password,
|
:password,
|
||||||
min: 6,
|
min: 6,
|
||||||
max: 100,
|
max: 100,
|
||||||
message: "registration.error.password_too_short"
|
message: "The choosen password is too short."
|
||||||
)
|
)
|
||||||
|
|
||||||
if Map.has_key?(attrs, :default_actor) do
|
if Map.has_key?(attrs, :default_actor) do
|
||||||
|
@ -57,21 +58,13 @@ defmodule Mobilizon.Actors.User do
|
||||||
def registration_changeset(struct, params) do
|
def registration_changeset(struct, params) do
|
||||||
struct
|
struct
|
||||||
|> changeset(params)
|
|> changeset(params)
|
||||||
|> cast(params, ~w(password)a, [])
|
|
||||||
|> cast_assoc(:default_actor)
|
|> cast_assoc(:default_actor)
|
||||||
|> validate_required([:email, :password])
|
|> validate_required([:email, :password])
|
||||||
|> validate_email()
|
|
||||||
|> validate_length(
|
|
||||||
:password,
|
|
||||||
min: 6,
|
|
||||||
max: 100,
|
|
||||||
message: "registration.error.password_too_short"
|
|
||||||
)
|
|
||||||
|> hash_password()
|
|> hash_password()
|
||||||
|> save_confirmation_token()
|
|> save_confirmation_token()
|
||||||
|> unique_constraint(
|
|> unique_constraint(
|
||||||
:confirmation_token,
|
:confirmation_token,
|
||||||
message: "regisration.error.confirmation_token_already_in_use"
|
message: "The registration is already in use, this looks like an issue on our side."
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||||
Handles the person-related GraphQL calls
|
Handles the person-related GraphQL calls
|
||||||
"""
|
"""
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.{Actor, User}
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Service.ActivityPub
|
||||||
|
|
||||||
@deprecated "Use find_person/3 or find_group/3 instead"
|
@deprecated "Use find_person/3 or find_group/3 instead"
|
||||||
|
@ -52,6 +52,9 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||||
{:error, "You need to be logged-in to view your list of identities"}
|
{:error, "You need to be logged-in to view your list of identities"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
This function is used to create more identities from an existing user
|
||||||
|
"""
|
||||||
def create_person(_parent, %{preferred_username: _preferred_username} = args, %{
|
def create_person(_parent, %{preferred_username: _preferred_username} = args, %{
|
||||||
context: %{current_user: user}
|
context: %{current_user: user}
|
||||||
}) do
|
}) do
|
||||||
|
@ -59,9 +62,23 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||||
|
|
||||||
with {:ok, %Actor{} = new_person} <- Actors.new_person(args) do
|
with {:ok, %Actor{} = new_person} <- Actors.new_person(args) do
|
||||||
{:ok, new_person}
|
{:ok, new_person}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
This function is used to register a person afterwards the user has been created (but not activated)
|
||||||
|
"""
|
||||||
|
def register_person(_parent, args, _resolution) do
|
||||||
|
with {:ok, %User{} = user} <- Actors.get_user_by_email(args.email),
|
||||||
|
{:no_actor, nil} <- {:no_actor, Actors.get_actor_for_user(user)},
|
||||||
|
args <- Map.put(args, :user_id, user.id),
|
||||||
|
{:ok, %Actor{} = new_person} <- Actors.new_person(args) do
|
||||||
|
{:ok, new_person}
|
||||||
else
|
else
|
||||||
{:error, %Ecto.Changeset{} = _e} ->
|
{:error, :user_not_found} ->
|
||||||
{:error, "Unable to create a profile with this username"}
|
{:error, "User with email not found"}
|
||||||
|
{:no_actor, _} ->
|
||||||
|
{:error, "You already have a profile for this user"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule MobilizonWeb.Schema.Actors.PersonType do
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias MobilizonWeb.Resolvers
|
alias MobilizonWeb.Resolvers
|
||||||
|
import MobilizonWeb.Schema.Utils
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Represents a person identity
|
Represents a person identity
|
||||||
|
@ -69,11 +70,24 @@ defmodule MobilizonWeb.Schema.Actors.PersonType do
|
||||||
@desc "Create a new person for user"
|
@desc "Create a new person for user"
|
||||||
field :create_person, :person do
|
field :create_person, :person do
|
||||||
arg(:preferred_username, non_null(:string))
|
arg(:preferred_username, non_null(:string))
|
||||||
arg(:name, :string, description: "The displayed name for the new profile")
|
|
||||||
|
|
||||||
arg(:description, :string, description: "The summary for the new profile", default_value: "")
|
arg(:name, :string, description: "The displayed name for the new profile", default_value: "")
|
||||||
|
|
||||||
resolve(&Resolvers.Person.create_person/3)
|
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
||||||
|
|
||||||
|
resolve(handle_errors(&Resolvers.Person.create_person/3))
|
||||||
|
end
|
||||||
|
|
||||||
|
@desc "Register a first profile on registration"
|
||||||
|
field :register_person, :person do
|
||||||
|
arg(:preferred_username, non_null(:string))
|
||||||
|
|
||||||
|
arg(:name, :string, description: "The displayed name for the new profile", default_value: "")
|
||||||
|
|
||||||
|
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
||||||
|
arg(:email, non_null(:string), description: "The email from the user previously created")
|
||||||
|
|
||||||
|
resolve(handle_errors(&Resolvers.Person.register_person/3))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,8 @@ defmodule MobilizonWeb.Schema.Utils do
|
||||||
# {:error, [email: {"has already been taken", []}]}
|
# {:error, [email: {"has already been taken", []}]}
|
||||||
errors =
|
errors =
|
||||||
changeset.errors
|
changeset.errors
|
||||||
|> Enum.map(fn {_key, {value, context}} ->
|
|> Enum.map(fn {key, {value, _context}} ->
|
||||||
[message: "#{value}", details: context]
|
[message: "#{value}", details: key]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:error, errors}
|
{:error, errors}
|
||||||
|
|
|
@ -73,21 +73,25 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Resolver: Create an user & actor" do
|
describe "Resolver: Create an user & actor" do
|
||||||
@account_creation %{
|
@user_creation %{
|
||||||
email: "test@demo.tld",
|
email: "test@demo.tld",
|
||||||
password: "long password"
|
password: "long password",
|
||||||
|
username: "toto",
|
||||||
|
name: "Sir Toto",
|
||||||
|
summary: "Sir Toto, prince of the functional tests"
|
||||||
}
|
}
|
||||||
@account_creation_bad_email %{
|
@user_creation_bad_email %{
|
||||||
email: "y@l@",
|
email: "y@l@",
|
||||||
password: "long password"
|
password: "long password"
|
||||||
}
|
}
|
||||||
|
|
||||||
test "test create_user/3 creates an user", context do
|
test "test create_user/3 creates an user and register_person/3 registers a profile",
|
||||||
|
context do
|
||||||
mutation = """
|
mutation = """
|
||||||
mutation {
|
mutation {
|
||||||
createUser(
|
createUser(
|
||||||
email: "#{@account_creation.email}",
|
email: "#{@user_creation.email}",
|
||||||
password: "#{@account_creation.password}",
|
password: "#{@user_creation.password}",
|
||||||
) {
|
) {
|
||||||
id,
|
id,
|
||||||
email
|
email
|
||||||
|
@ -99,15 +103,141 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
context.conn
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["createUser"]["email"] == @account_creation.email
|
assert json_response(res, 200)["data"]["createUser"]["email"] == @user_creation.email
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
registerPerson(
|
||||||
|
preferredUsername: "#{@user_creation.username}",
|
||||||
|
name: "#{@user_creation.name}",
|
||||||
|
summary: "#{@user_creation.summary}",
|
||||||
|
email: "#{@user_creation.email}",
|
||||||
|
) {
|
||||||
|
preferredUsername,
|
||||||
|
name,
|
||||||
|
summary,
|
||||||
|
avatarUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
context.conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert json_response(res, 200)["data"]["registerPerson"]["preferredUsername"] ==
|
||||||
|
@user_creation.username
|
||||||
|
end
|
||||||
|
|
||||||
|
test "register_person/3 doesn't register a profile from an unknown email", context do
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
createUser(
|
||||||
|
email: "#{@user_creation.email}",
|
||||||
|
password: "#{@user_creation.password}",
|
||||||
|
) {
|
||||||
|
id,
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
context.conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
registerPerson(
|
||||||
|
preferredUsername: "#{@user_creation.username}",
|
||||||
|
name: "#{@user_creation.name}",
|
||||||
|
summary: "#{@user_creation.summary}",
|
||||||
|
email: "random",
|
||||||
|
) {
|
||||||
|
preferredUsername,
|
||||||
|
name,
|
||||||
|
summary,
|
||||||
|
avatarUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
context.conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||||
|
"User with email not found"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "register_person/3 can't be called with an existing profile", context do
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
createUser(
|
||||||
|
email: "#{@user_creation.email}",
|
||||||
|
password: "#{@user_creation.password}",
|
||||||
|
) {
|
||||||
|
id,
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
context.conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
registerPerson(
|
||||||
|
preferredUsername: "#{@user_creation.username}",
|
||||||
|
name: "#{@user_creation.name}",
|
||||||
|
summary: "#{@user_creation.summary}",
|
||||||
|
email: "#{@user_creation.email}",
|
||||||
|
) {
|
||||||
|
preferredUsername,
|
||||||
|
name,
|
||||||
|
summary,
|
||||||
|
avatarUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
context.conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert json_response(res, 200)["data"]["registerPerson"]["preferredUsername"] ==
|
||||||
|
@user_creation.username
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
registerPerson(
|
||||||
|
preferredUsername: "#{@user_creation.username}",
|
||||||
|
name: "#{@user_creation.name}",
|
||||||
|
summary: "#{@user_creation.summary}",
|
||||||
|
email: "#{@user_creation.email}",
|
||||||
|
) {
|
||||||
|
preferredUsername,
|
||||||
|
name,
|
||||||
|
summary,
|
||||||
|
avatarUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
context.conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||||
|
"You already have a profile for this user"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "test create_user/3 doesn't create an user with bad email", context do
|
test "test create_user/3 doesn't create an user with bad email", context do
|
||||||
mutation = """
|
mutation = """
|
||||||
mutation {
|
mutation {
|
||||||
createUser(
|
createUser(
|
||||||
email: "#{@account_creation_bad_email.email}",
|
email: "#{@user_creation_bad_email.email}",
|
||||||
password: "#{@account_creation.password}",
|
password: "#{@user_creation_bad_email.password}",
|
||||||
) {
|
) {
|
||||||
id,
|
id,
|
||||||
email
|
email
|
||||||
|
|
Loading…
Reference in a new issue