Fix resend confirmation component

This commit is contained in:
Chocobozzz 2019-01-11 14:07:14 +01:00
parent 91b26bacef
commit 290b31f031
6 changed files with 35 additions and 21 deletions

View File

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

View File

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

View File

@ -32,7 +32,7 @@
<script lang="ts">
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';
@Component
@ -53,7 +53,7 @@
rules = {
required: validateRequiredField,
email: validateEmail,
email: validateEmailField,
};
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.';
}

View File

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