Skip to content

Instantly share code, notes, and snippets.

@santiblanko
Created August 8, 2019 19:54
Show Gist options
  • Save santiblanko/951e7ea3203595a1f1cb8314386ea6cd to your computer and use it in GitHub Desktop.
Save santiblanko/951e7ea3203595a1f1cb8314386ea6cd to your computer and use it in GitHub Desktop.
<template>
<div>
<div class="content">
<div class="row mt-4">
<div class="col-md-12">
<div class="row mt-3">
<div class="col-md-4 offset-md-4">
<div class="block block-fx-pop">
<div class="block-content">
<div class="form-group" v-if="error">
<el-alert
show-icon
title="Error al iniciar sesión"
:description="error.message"
type="error"
></el-alert>
</div>
<div class="form-group">
<center>
<img width="100" src="/static/logo2.png" alt>
</center>
<hr>
</div>
<div class="form-group">
<label for="example-text-input-alt">Email</label>
<input
v-model="email"
type="text"
class="form-control form-control-alt"
id="example-text-input-alt"
placeholder="Email"
>
</div>
<div class="form-group">
<label for="example-text-input-alt">Password</label>
<input
v-model="password"
type="password"
class="form-control form-control-alt"
id="example-text-input-alt"
placeholder="Password"
>
</div>
<button @click="goToMain" class="btn-outline-primary btn mb-5">
<i class="fa fa-home"></i>
Cancelar
</button>
<button
@click="login"
class="btn-primary btn mb-5"
>
<i class="fa fa-key"></i>
Iniciar sesión
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
error: null,
email: "",
password: ""
};
},
mounted() {
delete this.axios.defaults.headers.common["Authorization"];
},
methods: {
auth(obj) {
this.$auth.token(obj.data.jwt);
this.$auth.user(obj.data.user);
},
showError(error) {
this.error = error.response.data;
if (this.error == "Incorrect password") {
this.error = "Password incorrecto";
}
if (this.error == "Cannot find user") {
this.error = "El usuario no existe";
}
if (this.error == "Email and password are required") {
this.error = "El email y el password es requerido";
}
},
login() {
this.$auth
.login({
data: {
identifier: this.email,
password: this.password
},
rememberMe: true
})
.then(this.auth)
.catch(this.showError);
},
goToMain() {
this.$router.push("/");
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment