2022-06-27 21:59:35 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="full-h is-flex is-justify-content-center is-align-items-center my-5"
|
|
|
|
>
|
|
|
|
<form class="box">
|
|
|
|
<div class="has-text-centered">
|
|
|
|
<h2 class="is-size-1">PC Puma</h2>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<b-field label="Usuario" :type="error">
|
|
|
|
<b-input v-model="usuario" @keyup.enter.native="login()" />
|
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<b-field label="Contraseña" :type="error">
|
|
|
|
<b-input
|
|
|
|
type="password"
|
|
|
|
@keyup.enter.native="login()"
|
2022-08-07 05:12:52 +00:00
|
|
|
v-model="password"
|
|
|
|
password-reveal
|
2022-06-27 21:59:35 +00:00
|
|
|
/>
|
|
|
|
</b-field>
|
|
|
|
|
2022-08-09 20:14:51 +00:00
|
|
|
<b-field>
|
|
|
|
<recaptcha />
|
|
|
|
</b-field>
|
|
|
|
|
2022-06-27 21:59:35 +00:00
|
|
|
<div class="has-text-centered">
|
|
|
|
<b-button
|
|
|
|
@click="login()"
|
|
|
|
type="is-success"
|
|
|
|
:disabled="error || !usuario || !password"
|
|
|
|
>
|
|
|
|
Iniciar Sesión
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
updateIsLoading: { type: Function, required: true },
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
error: '',
|
|
|
|
usuario: '',
|
|
|
|
password: '',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-08-09 20:14:51 +00:00
|
|
|
async login() {
|
|
|
|
const token = await this.$recaptcha.getResponse().catch((err) => {
|
|
|
|
this.$alertsGenericos.imprimirError(
|
|
|
|
this.$buefy,
|
|
|
|
this.$router,
|
|
|
|
'Favor de completar el recaptcha'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (this.usuario && this.password && token && !this.error) {
|
2022-06-27 21:59:35 +00:00
|
|
|
const data = {
|
|
|
|
operador: this.usuario,
|
|
|
|
password: this.password,
|
|
|
|
}
|
2022-08-07 05:12:52 +00:00
|
|
|
|
2022-06-27 21:59:35 +00:00
|
|
|
this.updateIsLoading(true)
|
|
|
|
axios
|
2022-08-09 20:14:51 +00:00
|
|
|
.post(`${process.env.api}/auth/login-admin`, data, {
|
|
|
|
headers: { recaptcha: token },
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
2022-07-29 19:34:21 +00:00
|
|
|
const token = res.data.token
|
|
|
|
const operador = JSON.stringify(res.data.operador)
|
|
|
|
|
|
|
|
localStorage.setItem('operador', operador)
|
|
|
|
localStorage.setItem('token', token)
|
2022-08-09 20:14:51 +00:00
|
|
|
await this.$recaptcha.reset()
|
2022-06-27 21:59:35 +00:00
|
|
|
this.updateIsLoading(false)
|
2022-08-07 05:12:52 +00:00
|
|
|
if (res.data.operador.tipoUsuario.id_tipo_usuario === 2)
|
2022-07-29 14:16:12 +00:00
|
|
|
this.$router.push(
|
|
|
|
'/admin/configuracion/instituciones/buscar_institucion'
|
|
|
|
)
|
2022-08-07 05:12:52 +00:00
|
|
|
else this.$router.push('/prestamo_devolucion')
|
2022-06-27 21:59:35 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.error = 'is-danger'
|
|
|
|
this.updateIsLoading(false)
|
2022-08-05 23:41:37 +00:00
|
|
|
this.$alertsGenericos.imprimirError(
|
|
|
|
this.$buefy,
|
|
|
|
this.$router,
|
|
|
|
err.response.data
|
|
|
|
)
|
2022-06-27 21:59:35 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
password() {
|
|
|
|
if (this.error) this.error = ''
|
|
|
|
},
|
|
|
|
usuario() {
|
|
|
|
if (this.error) this.error = ''
|
|
|
|
},
|
|
|
|
},
|
2022-08-09 20:14:51 +00:00
|
|
|
beforeDestroy() {
|
|
|
|
this.$recaptcha.destroy()
|
|
|
|
},
|
2022-06-27 21:59:35 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.full-h {
|
|
|
|
height: 75vh;
|
|
|
|
}
|
|
|
|
|
|
|
|
form {
|
|
|
|
width: 30rem;
|
|
|
|
}
|
|
|
|
</style>
|