-
-
Save KABBOUCHI/bba780c564f3c60b2f40d73806c8ef6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| axios.defaults.headers.common = { | |
| 'X-CSRF-TOKEN': window.csrfToken, | |
| 'X-Requested-With': 'XMLHttpRequest', | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <form @submit.prevent="onSubmit"> | |
| <b-field label="Email" | |
| :message="formErrors.first('email')" | |
| :type="formErrors.has('email') ? 'is-warning' : ''"> | |
| <b-input type="email" | |
| name="email" | |
| @input="clearErrors" | |
| v-model="formData.email" | |
| v-validate="{required: true, email: true}"> | |
| </b-input> | |
| </b-field> | |
| <b-field :label="$t('auth.password')" | |
| :message="formErrors.first('password')" | |
| :type="formErrors.has('password') ? 'is-warning' : ''"> | |
| <b-input type="password" | |
| name="password" | |
| @input="clearErrors" | |
| v-model="formData.password" | |
| v-validate="{required: true, min: 6}" | |
| password-reveal></b-input> | |
| </b-field> | |
| <b-notification v-if="formErrors.has('failed-auth.email')" | |
| type="is-warning" | |
| @close="clearErrors"> | |
| {{ this.formErrors.first('failed-auth.email') }} | |
| </b-notification> | |
| <div class="level"> | |
| <div class="level-left"> | |
| <div class="level-item"> | |
| <button type="submit" | |
| class="button is-primary" | |
| :class="isLoading ? 'is-loading' : ''" | |
| :disabled="isLoading || isFormPristine || formErrors.any()"> | |
| {{ $t("auth.login") }} | |
| </button> | |
| </div> | |
| </div> | |
| <div class="level-right is-size-7"> | |
| <div class="level-item"> | |
| {{ $t("auth.login_with") }} | |
| </div> | |
| <div class="level-item"> | |
| <a class="button is-small" href="/login/facebook"> | |
| <span class="icon is-small"> | |
| <i class="fab fa-facebook"></i> | |
| </span> | |
| <span>Facebook</span> | |
| </a> | |
| </div> | |
| <div class="level-item"> | |
| <a class="button is-small" href="/login/google"> | |
| <span class="icon is-small"> | |
| <i class="fab fa-google"></i> | |
| </span> | |
| <span>Google</span> | |
| </a> | |
| </div> | |
| </div> | |
| </div> | |
| </form> | |
| </template> | |
| <script> | |
| import isLoading from 'mixins/isLoading'; | |
| import {each} from 'lodash'; | |
| export default { | |
| mixins: [ | |
| isLoading | |
| ], | |
| data() { | |
| return { | |
| formData: { | |
| email: '', | |
| password: '' | |
| } | |
| } | |
| }, | |
| computed: { | |
| isFormPristine() { | |
| return Object.keys(this.fields).some(key => this.fields[key].pristine); | |
| } | |
| }, | |
| methods: { | |
| onSubmit() { | |
| this.$validator.validateAll().then((result) => { | |
| // send your data to the backend. | |
| if (result) { | |
| this.submitForm(); | |
| } | |
| }).catch(() => { | |
| // client side errors. | |
| }); | |
| }, | |
| submitForm() { | |
| this.loading = true; | |
| this.axios.post('/login', this.formData).then((response) => { | |
| window.location.href = '/'; | |
| }).catch((error) => { | |
| each(error.response.data.errors, (error, key) => { | |
| this.formErrors.add(key, error[0], null, 'failed-auth') | |
| }) | |
| this.loading = false; | |
| }); | |
| }, | |
| clearErrors() { | |
| this.formErrors.clear('failed-auth'); | |
| } | |
| } | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment