Add extra fields to registration, remove unused fields

This commit is contained in:
Christian Cueni 2020-02-06 15:14:35 +01:00
parent 587d661ca8
commit a0eeec4e18
6 changed files with 128 additions and 162 deletions

View File

@ -0,0 +1,3 @@
mutation($helloEmail: String!) {
helloEmail(email: $helloEmail) @client
}

View File

@ -9,9 +9,9 @@ export const resolvers = {
cache.writeQuery({query: SCROLL_POSITION, data}); cache.writeQuery({query: SCROLL_POSITION, data});
return data.scrollPosition; return data.scrollPosition;
}, },
helloEmail: (_, {helloEmail}, {cache}) => { helloEmail: (_, {email}, {cache}) => {
const data = cache.readQuery({query: HELLO_EMAIL}); const data = cache.readQuery({query: HELLO_EMAIL});
data.helloEmail.helloEmail = helloEmail; data.helloEmail.email = email;
cache.writeQuery({query: HELLO_EMAIL, data}); cache.writeQuery({query: HELLO_EMAIL, data});
return data.helloEmail; return data.helloEmail;
}, },

View File

@ -11,7 +11,7 @@ import store from '@/store/index'
import VueScrollTo from 'vue-scrollto'; import VueScrollTo from 'vue-scrollto';
import VueAnalytics from 'vue-analytics'; import VueAnalytics from 'vue-analytics';
import {Validator, install as VeeValidate} from 'vee-validate/dist/vee-validate.minimal.esm.js'; import {Validator, install as VeeValidate} from 'vee-validate/dist/vee-validate.minimal.esm.js';
import {required, min, decimal} from 'vee-validate/dist/rules.esm.js'; import {required, min, decimal, confirmed} from 'vee-validate/dist/rules.esm.js';
import veeDe from 'vee-validate/dist/locale/de'; import veeDe from 'vee-validate/dist/locale/de';
import {dateFilter} from './filters/date-filter'; import {dateFilter} from './filters/date-filter';
import autoGrow from '@/directives/auto-grow' import autoGrow from '@/directives/auto-grow'
@ -77,6 +77,7 @@ const apolloProvider = new VueApollo({
Validator.extend('required', required); Validator.extend('required', required);
Validator.extend('min', min); Validator.extend('min', min);
Validator.extend('decimal', decimal); Validator.extend('decimal', decimal);
Validator.extend('confirmed', confirmed);
const dict = { const dict = {
custom: { custom: {

View File

@ -39,7 +39,7 @@
<script> <script>
import {emailExists} from '../hep-client/index'; import {emailExists} from '../hep-client/index';
import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/helloEmail.gql'; import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/mutations/helloEmail.gql';
export default { export default {
components: {}, components: {},
@ -59,7 +59,7 @@ export default {
this.$apollo.mutate({ this.$apollo.mutate({
mutation: HELLO_EMAIL_MUTATION, mutation: HELLO_EMAIL_MUTATION,
variables: { variables: {
email: this.email helloEmail: this.email
} }
}) })

View File

@ -1,33 +1,10 @@
<template> <template>
<div class="login public-page"> <div class="login public-page">
<h1 class="login__title public-page__title">Melden Sie sich jetzt an</h1> <header>
<p>Super wir haben für {{helloEmail.email}} ein Hep Konto gefunden</p>
<h1 class="login__title public-page__title">Bitte geben Sie das passende Passwort ein</h1>
</header>
<form class="login__form login-form" novalidate @submit.prevent="validateBeforeSubmit"> <form class="login__form login-form" novalidate @submit.prevent="validateBeforeSubmit">
<div class="login-form__field skillboxform-input">
<label for="email" class="skillboxform-input__label">E-Mail</label>
<input
id="email"
name="email"
type="text"
v-model="email"
v-validate="'required'"
data-vv-as="E-Mail"
:class="{ 'skillboxform-input__input--error': errors.has('email') }"
class="change-form__email skillbox-input skillboxform-input__input"
autocomplete="off"
data-cy="email-input"
/>
<small
v-if="errors.has('email') && submitted"
class="skillboxform-input__error"
data-cy="email-local-errors"
>{{ errors.first('email') }}</small>
<small
v-for="error in emailErrors"
:key="error"
class="skillboxform-input__error"
data-cy="email-remote-errors"
>{{ error }}</small>
</div>
<div class="change-form__field skillboxform-input"> <div class="change-form__field skillboxform-input">
<label for="pw" class="skillboxform-input__label">Passwort</label> <label for="pw" class="skillboxform-input__label">Passwort</label>
<input <input
@ -41,6 +18,7 @@
class="change-form__new skillbox-input skillboxform-input__input" class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off" autocomplete="off"
data-cy="password-input" data-cy="password-input"
tabindex="0"
/> />
<small <small
v-if="errors.has('password') && submitted" v-if="errors.has('password') && submitted"
@ -61,17 +39,14 @@
<button class="button button--primary button--big actions__submit" data-cy="login-button">Anmelden</button> <button class="button button--primary button--big actions__submit" data-cy="login-button">Anmelden</button>
<a class="actions__reset text-link" href="/accounts/password_reset/">Passwort vergessen?</a> <a class="actions__reset text-link" href="/accounts/password_reset/">Passwort vergessen?</a>
</div> </div>
<div class="account-link">
<p class="account-link__text">Haben Sie noch kein Konto?</p>
<router-link class="account-link__link text-link" :to="{name: 'registration'}">Jetzt registrieren
</router-link>
</div>
</form> </form>
</div> </div>
</template> </template>
<script> <script>
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql';
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import {login} from '../hep-client/index';
export default { export default {
components: {}, components: {},
@ -82,42 +57,58 @@ export default {
this.submitted = true; this.submitted = true;
let that = this; let that = this;
if (result) { if (result) {
this.$apollo.mutate({
client: 'publicClient', login(this.password)
mutation: LOGIN_MUTATION, .then((response) => {
variables: { console.log(response)
input: { })
usernameInput: this.email, .catch((error) => {
passwordInput: this.password console.log(error)
} this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
},
fetchPolicy: 'no-cache',
}).then(({data: {login}}) => {
try {
if (login.success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
that.$router.push(redirectUrl);
} else {
const firstError = login.errors[0];
switch (firstError.field) {
case 'invalid_credentials':
that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';
break;
case 'license_inactive':
that.loginError = 'Ihre Lizenz ist nicht mehr aktiv.';
break;
}
}
} catch (e) {
console.warn(e);
that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
}
}); });
// this.$apollo.mutate({
// client: 'publicClient',
// mutation: LOGIN_MUTATION,
// variables: {
// input: {
// usernameInput: this.email,
// passwordInput: this.password
// }
// },
// update(
// store,
// {
// data: {
// login
// }
// }
// ) {
// try {
// if (login.success) {
// const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
// that.$router.push(redirectUrl);
// } else {
// const firstError = login.errors[0];
// switch (firstError.field) {
// case 'invalid_credentials':
// that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';
// break;
// case 'license_inactive':
// that.loginError = 'Ihre Lizenz ist nicht mehr aktiv.';
// break;
// }
// }
// } catch (e) {
// console.warn(e);
// that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
// }
// }
// });
} }
}); });
}, },
resetForm() { resetForm() {
this.email = '';
this.password = ''; this.password = '';
this.submitted = false; this.submitted = false;
this.$validator.reset(); this.$validator.reset();
@ -126,14 +117,18 @@ export default {
data() { data() {
return { return {
email: '',
password: '', password: '',
emailErrors: [],
passwordErrors: [], passwordErrors: [],
loginError: '', loginError: '',
submitted: false submitted: false
}; };
} },
apollo: {
helloEmail: {
query: HELLO_EMAIL
},
},
}; };
</script> </script>

View File

@ -1,8 +1,12 @@
<template> <template>
<div class="registration public-page"> <div class="registration public-page">
<h1 class="registration__title public-page__title">Registrieren Sie ihr persönliches Konto.</h1> <header>
<p>Für {{helloEmail.email}} haben wir kein Hep Konto gefunden.</p>
<h1 class="registration__title public-page__title">Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.</h1>
</header>
<form class="registration__form registration-form" novalidate @submit.prevent="validateBeforeSubmit"> <form class="registration__form registration-form" novalidate @submit.prevent="validateBeforeSubmit">
<div class="registration-form__field skillboxform-input"> <div class="registration-form__field skillboxform-input">
<div class="registration-form__field skillboxform-input">
<label for="prefix" class="skillboxform-input__label">Anrede</label> <label for="prefix" class="skillboxform-input__label">Anrede</label>
<select <select
id="prefix" id="prefix"
@ -19,7 +23,6 @@
<option>Frau</option> <option>Frau</option>
</select> </select>
</div> </div>
<div class="registration-form__field skillboxform-input">
<label for="firstname" class="skillboxform-input__label">Vorname</label> <label for="firstname" class="skillboxform-input__label">Vorname</label>
<input <input
id="firstname" id="firstname"
@ -71,7 +74,7 @@
data-cy="lastname-remote-errors" data-cy="lastname-remote-errors"
>{{ error }}</small> >{{ error }}</small>
</div> </div>
<div class="change-form__field skillboxform-input"> <!-- <div class="change-form__field skillboxform-input">
<label for="email" class="skillboxform-input__label">E-Mail</label> <label for="email" class="skillboxform-input__label">E-Mail</label>
<input <input
id="email" id="email"
@ -96,96 +99,67 @@
class="skillboxform-input__error" class="skillboxform-input__error"
data-cy="email-remote-errors" data-cy="email-remote-errors"
>{{ error }}</small> >{{ error }}</small>
</div> </div> -->
<div class="change-form__field skillboxform-input"> <div class="change-form__field skillboxform-input">
<label for="address" class="skillboxform-input__label">Adresse</label> <label for="password" class="skillboxform-input__label">Passwort</label>
<input <input
id="address" id="password"
name="address" name="password"
type="text" type="text"
v-model="address" v-model="password"
data-vv-as="Adresse" data-vv-as="Passwort"
v-validate="'required'" v-validate="'required|strongPassword'"
:class="{ 'skillboxform-input__input--error': errors.has('address') }" :class="{ 'skillboxform-input__input--error': errors.has('password') }"
class="change-form__new skillbox-input skillboxform-input__input" class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off" autocomplete="off"
data-cy="address-input" data-cy="password-input"
ref="password"
/> />
<small <small
v-if="errors.has('address') && submitted" v-if="errors.has('password') && submitted"
class="skillboxform-input__error" class="skillboxform-input__error"
data-cy="address-local-errors" data-cy="password-local-errors"
>{{ errors.first('address') }}</small> >{{ errors.first('password') }}</small>
<small <small
v-for="error in addressErrors" v-for="error in passwordErrors"
:key="error" :key="error"
class="skillboxform-input__error" class="skillboxform-input__error"
data-cy="address-remote-errors" data-cy="password-remote-errors"
>{{ error }}</small> >{{ error }}</small>
</div> </div>
<div class="change-form__field skillboxform-input"> <div class="change-form__field skillboxform-input">
<label for="zipCode" class="skillboxform-input__label">PLZ</label> <label for="password2" class="skillboxform-input__label">Passwort wiederholen</label>
<input <input
id="zipCode" id="passwordConfirmation"
name="zipCode" name="passwordConfirmation"
type="number"
v-model="zipCode"
data-vv-as="PLZ"
v-validate="'required'"
:class="{ 'skillboxform-input__input--error': errors.has('zipCode') }"
class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off"
data-cy="zipCode-input"
/>
<small
v-if="errors.has('zipCode') && submitted"
class="skillboxform-input__error"
data-cy="zipCode-local-errors"
>{{ errors.first('zipCode') }}</small>
<small
v-for="error in zipCodeErrors"
:key="error"
class="skillboxform-input__error"
data-cy="zipCode-remote-errors"
>{{ error }}</small>
</div>
<div class="change-form__field skillboxform-input">
<label for="city" class="skillboxform-input__label">Ort</label>
<input
id="city"
name="city"
type="text" type="text"
v-model="city" v-model="passwordConfirmation"
data-vv-as="Ort" data-vv-as="Passwort wiederholen"
v-validate="'required'" v-validate="'required|confirmed:password'"
:class="{ 'skillboxform-input__input--error': errors.has('city') }" :class="{ 'skillboxform-input__input--error': errors.has('passwordConfirmation') }"
class="change-form__new skillbox-input skillboxform-input__input" class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off" autocomplete="off"
data-cy="city-input" data-cy="passwordConfirmation-input"
/> />
<small <small
v-if="errors.has('city') && submitted" v-if="errors.has('passwordConfirmation') && submitted"
class="skillboxform-input__error" class="skillboxform-input__error"
data-cy="city-local-errors" data-cy="password-local-errors"
>{{ errors.first('city') }}</small> >{{ errors.first('passwordConfirmation') }}</small>
<small <small
v-for="error in cityErrors" v-for="error in passwordErrors"
:key="error" :key="error"
class="skillboxform-input__error" class="skillboxform-input__error"
data-cy="city-remote-errors" data-cy="password-remote-errors"
>{{ error }}</small> >{{ error }}</small>
</div> </div>
<div class="skillboxform-input"> <div class="skillboxform-input">
<small class="skillboxform-input__error" data-cy="registration-error" v-if="registrationError">{{registrationError}}</small> <small class="skillboxform-input__error" data-cy="registration-error" v-if="registrationError">{{registrationError}}</small>
</div> </div>
<div class="actions"> <div class="actions">
<button class="button button--primary button--big actions__submit" data-cy="register-button">Jetzt registrieren</button> <button class="button button--primary button--big actions__submit" data-cy="register-button">Konto erstellen</button>
</div>
<div class="account-link">
<p class="account-link__text">Haben Sie ein Konto?</p>
<router-link class="account-link__link text-link" :to="{name: 'login'}">Jetzt anmelden
</router-link>
</div> </div>
</form> </form>
</div> </div>
</template> </template>
@ -193,6 +167,7 @@
<script> <script>
import {register} from '../hep-client/index' import {register} from '../hep-client/index'
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
export default { export default {
components: {}, components: {},
@ -205,21 +180,12 @@ export default {
const registrationData = { const registrationData = {
customer: { customer: {
prefix: this.prefix, prefix: this.prefix,
email: this.email, email: this.helloEmail.email,
firstname: this.firstname, firstname: this.firstname,
lastname: this.lastname, lastname: this.lastname,
gender: this.prefix === 'Herr' ? 1 : 2, gender: this.prefix === 'Herr' ? 1 : 2,
addresses: [{ },
country_id: 'CH', password: this.password
street: [this.address],
postcode: this.address,
city: this.city,
firstname: this.firstname,
lastname: this.lastname,
default_shipping: true,
default_billing: true
}]
}
}; };
register(registrationData).then((response) => { register(registrationData).then((response) => {
@ -240,18 +206,15 @@ export default {
}, },
resetForm() { resetForm() {
this.prefix = ''; this.prefix = '';
this.email = '';
this.lastname = ''; this.lastname = '';
this.firstname = ''; this.firstname = '';
this.zipCode = ''; this.password = '';
this.address = ''; this.passwordConfirmation = '';
this.city = '';
this.firstnameErrors = []; this.firstnameErrors = [];
this.lastnameErrors = []; this.lastnameErrors = [];
this.emailErrors = []; this.emailErrors = [];
this.zipCodeErrors = []; this.passwordsError = [];
this.addressErrors = []; this.passwordError = [];
this.cityErrors = [];
this.registrationError = []; this.registrationError = [];
this.submitted = false; this.submitted = false;
this.$validator.reset(); this.$validator.reset();
@ -261,22 +224,26 @@ export default {
data() { data() {
return { return {
prefix: '', prefix: '',
email: '',
lastname: '', lastname: '',
firstname: '', firstname: '',
zipCode: '', password: '',
address: '', passwordConfirmation: '',
city: '',
firstnameErrors: '', firstnameErrors: '',
lastnameErrors: '', lastnameErrors: '',
emailErrors: '', emailErrors: '',
zipCodeErrors: '', passwordsErrors: [],
addressErrors: '', passwordErrors: [],
cityErrors: '',
registrationError: '', registrationError: '',
submitted: false submitted: false
}; };
} },
apollo: {
helloEmail: {
query: HELLO_EMAIL
},
},
}; };
</script> </script>