From 91b26bacefc65d3da3d6de1899a728fd6dca502b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Jan 2019 13:58:29 +0100 Subject: [PATCH] Fix reset password component --- js/src/components/Account/Login.vue | 18 +++---- js/src/components/Account/PasswordReset.vue | 51 +++++++++---------- .../components/Account/SendPasswordReset.vue | 39 +++++++------- js/src/graphql/auth.ts | 17 +++++++ js/src/types/login.model.ts | 7 +++ js/src/utils/auth.ts | 7 +++ js/src/utils/validators.ts | 7 +++ lib/mobilizon_web/resolvers/user.ex | 2 +- 8 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 js/src/types/login.model.ts create mode 100644 js/src/utils/auth.ts create mode 100644 js/src/utils/validators.ts diff --git a/js/src/components/Account/Login.vue b/js/src/components/Account/Login.vue index cfc319cf6..f457fda6f 100644 --- a/js/src/components/Account/Login.vue +++ b/js/src/components/Account/Login.vue @@ -62,9 +62,11 @@ import Gravatar from 'vue-gravatar'; import RegisterAvatar from './RegisterAvatar.vue'; - import { AUTH_TOKEN, AUTH_USER_ACTOR, AUTH_USER_ID } from '@/constants'; import { Component, Prop, Vue } from 'vue-property-decorator'; import { LOGIN } from '@/graphql/auth'; + import { validateEmail, validateRequiredField } from '@/utils/validators'; + import { saveUserData } from '@/utils/auth'; + import { ILogin } from '@/types/login.model' @Component({ components: { @@ -91,8 +93,8 @@ }, }; rules = { - required: value => !!value || 'Required.', - email: (value) => value.includes('@') || 'Invalid e-mail.', + required: validateRequiredField, + email: validateEmail }; user: any; @@ -109,9 +111,10 @@ async loginAction(e: Event) { e.preventDefault(); + this.error.show = false; try { - const result = await this.$apollo.mutate({ + const result = await this.$apollo.mutate<{ login: ILogin }>({ mutation: LOGIN, variables: { email: this.credentials.email, @@ -119,7 +122,7 @@ }, }); - this.saveUserData(result.data); + saveUserData(result.data.login); this.$router.push({ name: 'Home' }); } catch (err) { console.error(err); @@ -131,10 +134,5 @@ validEmail() { return this.rules.email(this.credentials.email) === true ? 'v-gravatar' : 'avatar'; } - - saveUserData({ login: login }) { - localStorage.setItem(AUTH_USER_ID, login.user.id); - localStorage.setItem(AUTH_TOKEN, login.token); - } } diff --git a/js/src/components/Account/PasswordReset.vue b/js/src/components/Account/PasswordReset.vue index 12ffe0039..47ce03c7f 100644 --- a/js/src/components/Account/PasswordReset.vue +++ b/js/src/components/Account/PasswordReset.vue @@ -39,6 +39,10 @@