Created
April 14, 2020 10:55
-
-
Save Serhansolo/f9ff05689943d8cea17b3a06bce7055b to your computer and use it in GitHub Desktop.
This file contains 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> | |
<div class="columns" v-if="!isUserAuth"> | |
<div class="column is-half is-offset-one-quarter"> | |
<div class="card"> | |
<div class="card-content"> | |
<div | |
v-if="validationErrors.length" | |
class="notification is-danger is-light" | |
> | |
<button @click="resetError()" class="delete"></button> | |
<div class="content"> | |
Please resolve the following error(s) before proceeding. | |
<ul style="margin-top:0.3em; margin-left: 1em"> | |
<li | |
v-for="(error, index) in validationErrors" | |
:key="`error-${index}`" | |
v-html="error" | |
/> | |
</ul> | |
</div> | |
</div> | |
<form> | |
<div class="field"> | |
<label class="label">E-mail</label> | |
<div class="control"> | |
<input | |
v-model="email" | |
class="input" | |
type="text" | |
autocomplete="email" | |
placeholder="[email protected]" | |
/> | |
</div> | |
</div> | |
<div class="field"> | |
<label class="label">Password</label> | |
<div class="control"> | |
<input | |
v-model="password" | |
class="input" | |
type="password" | |
autocomplete="current-password" | |
placeholder="Password" | |
/> | |
</div> | |
</div> | |
<div class="field"> | |
<p class="control"> | |
<button @click.prevent="validate()" class="button is-success"> | |
Login | |
</button> | |
</p> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import { mapGetters, mapActions } from "vuex"; | |
export default { | |
data() { | |
return { | |
email: null, | |
password: null, | |
validationErrors: [], | |
firebaseError: "" | |
}; | |
}, | |
computed: { | |
...mapGetters(["isUserAuth"]) | |
}, | |
methods: { | |
...mapActions(["signInAction"]), | |
resetError() { | |
this.validationErrors = []; | |
}, | |
validate() { | |
// Clear the errors before we validate again | |
this.resetError(); | |
// email validation | |
if (!this.email) { | |
this.validationErrors.push("<strong>E-mail</strong> cannot be empty."); | |
} | |
if (/.+@.+/.test(this.email) != true) { | |
this.validationErrors.push("<strong>E-mail</strong> must be valid."); | |
} | |
// password validation | |
if (!this.password) { | |
this.validationErrors.push("<strong>Password</strong> cannot be empty"); | |
} | |
if (/.{6,}/.test(this.password) != true) { | |
this.validationErrors.push( | |
"<strong>Password</strong> must be at least 6 characters long" | |
); | |
} | |
// when valid then sign in | |
if (this.validationErrors.length <= 0) { | |
this.signIn(); | |
} | |
}, | |
signIn() { | |
this.signInAction({ email: this.email, password: this.password }); | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment