Created
April 6, 2020 20:41
-
-
Save Serhansolo/6147558ec651fc8597d1b656ff888248 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"> | |
<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"> | |
<label class="label">Repeat password</label> | |
<div class="control"> | |
<input | |
v-model="passwordRepeat" | |
class="input" | |
type="password" | |
autocomplete="new-password" | |
placeholder="Password" | |
/> | |
</div> | |
</div> | |
<div class="field"> | |
<p class="control"> | |
<button @click.prevent="validate()" class="button is-success"> | |
Register | |
</button> | |
</p> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import firebase from "firebase/app"; | |
export default { | |
data() { | |
return { | |
email: null, | |
password: null, | |
passwordRepeat: null, | |
validationErrors: [] | |
}; | |
}, | |
methods: { | |
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" | |
); | |
} | |
if (!(this.password === this.passwordRepeat)) { | |
this.validationErrors.push("<strong>Passwords</strong> did not match"); | |
} | |
// when valid then sign in | |
if (this.validationErrors.length <= 0) { | |
this.signUp(); | |
} | |
}, | |
signUp() { | |
// @TODO signUp logic will come here | |
firebase | |
.auth() | |
.createUserWithEmailAndPassword(this.email, this.password) | |
.then(response => { | |
console.log("Success! ", response); | |
}) | |
.catch(error => { | |
console.log("Failed!", error); | |
}); | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment