Fix resend confirmation component

This commit is contained in:
Chocobozzz 2019-01-11 14:07:14 +01:00
parent df4d3892c3
commit 4a77b2b1b7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 35 additions and 21 deletions

View File

@ -64,7 +64,7 @@
import RegisterAvatar from './RegisterAvatar.vue'; import RegisterAvatar from './RegisterAvatar.vue';
import { Component, Prop, Vue } from 'vue-property-decorator'; import { Component, Prop, Vue } from 'vue-property-decorator';
import { LOGIN } from '@/graphql/auth'; import { LOGIN } from '@/graphql/auth';
import { validateEmail, validateRequiredField } from '@/utils/validators'; import { validateEmailField, validateRequiredField } from '@/utils/validators';
import { saveUserData } from '@/utils/auth'; import { saveUserData } from '@/utils/auth';
import { ILogin } from '@/types/login.model' import { ILogin } from '@/types/login.model'
@ -94,7 +94,7 @@
}; };
rules = { rules = {
required: validateRequiredField, required: validateRequiredField,
email: validateEmail email: validateEmailField
}; };
user: any; user: any;

View File

@ -32,6 +32,8 @@
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'; import { Component, Prop, Vue } from 'vue-property-decorator';
import { validateEmailField, validateRequiredField } from '@/utils/validators';
import { RESEND_CONFIRMATION_EMAIL } from '@/graphql/auth';
@Component @Component
export default class ResendConfirmation extends Vue { export default class ResendConfirmation extends Vue {
@ -49,29 +51,32 @@
}, },
}; };
rules = { rules = {
required: value => !!value || 'Required.', required: validateRequiredField,
email: (value) => { email: validateEmailField,
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.';
},
}; };
mounted() { mounted() {
this.credentials.email = this.email; this.credentials.email = this.email;
} }
resendConfirmationAction(e) { async resendConfirmationAction(e) {
e.preventDefault(); e.preventDefault();
this.error = false;
// FIXME: implement fetchStory try {
// fetchStory('/users/resend', this.$store, { method: 'POST', body: JSON.stringify(this.credentials) }).then(() => { await this.$apollo.mutate({
// this.validationSent = true; mutation: RESEND_CONFIRMATION_EMAIL,
// }).catch((err) => { variables: {
// Promise.resolve(err).then(() => { email: this.credentials.email,
// this.error = true; },
// this.validationSent = true; });
// });
// }); } catch (err) {
console.error(err);
this.error = true;
} finally {
this.validationSent = true;
}
} }
}; };
</script> </script>

View File

@ -32,7 +32,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'; import { Component, Prop, Vue } from 'vue-property-decorator';
import { validateEmail, validateRequiredField } from '@/utils/validators'; import { validateEmailField, validateRequiredField } from '@/utils/validators';
import { SEND_RESET_PASSWORD } from '@/graphql/auth'; import { SEND_RESET_PASSWORD } from '@/graphql/auth';
@Component @Component
@ -53,7 +53,7 @@
rules = { rules = {
required: validateRequiredField, required: validateRequiredField,
email: validateEmail, email: validateEmailField,
}; };
mounted() { mounted() {

View File

@ -27,3 +27,9 @@ mutation ResetPassword($token: String!, $password: String!) {
}, },
} }
`; `;
export const RESEND_CONFIRMATION_EMAIL = gql`
mutation ResendConfirmationEmail($email: String!) {
resendConfirmationEmail(email: $email)
}
`;

View File

@ -1,4 +1,4 @@
export function validateEmail(value: string) { export function validateEmailField(value: string) {
return value.includes('@') || 'Invalid e-mail.'; return value.includes('@') || 'Invalid e-mail.';
} }

View File

@ -9,7 +9,10 @@ defmodule Mobilizon.Factory do
%Mobilizon.Actors.User{ %Mobilizon.Actors.User{
password_hash: "Jane Smith", password_hash: "Jane Smith",
email: sequence(:email, &"email-#{&1}@example.com"), email: sequence(:email, &"email-#{&1}@example.com"),
role: 0 role: 0,
confirmed_at: DateTime.utc_now(),
confirmation_sent_at: nil,
confirmation_token: nil
} }
end end