parent
32c83f416f
commit
a8a8790a1e
@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<section class="section-container">
|
||||
<v-row class="signin">
|
||||
<v-spacer />
|
||||
<v-col cols="10" sm="8" md="6" lg="4" class="text-center">
|
||||
<h2 class="grey--text lighten-4">LOGIN</h2>
|
||||
<validation-observer ref="observer">
|
||||
<v-form @submit.prevent="submit">
|
||||
<validation-provider
|
||||
v-slot="{ errors }"
|
||||
name="Username"
|
||||
rules="required"
|
||||
>
|
||||
<v-text-field
|
||||
v-model="username"
|
||||
:error-messages="errors"
|
||||
label="Username"
|
||||
required
|
||||
outlined
|
||||
dark
|
||||
filled
|
||||
dense
|
||||
></v-text-field>
|
||||
</validation-provider>
|
||||
<validation-provider
|
||||
v-slot="{ errors }"
|
||||
name="Password"
|
||||
rules="required"
|
||||
>
|
||||
<v-text-field
|
||||
v-model="password"
|
||||
:error-messages="errors"
|
||||
label="Password"
|
||||
:append-icon="showPass ? 'mdi-eye' : 'mdi-eye-off'"
|
||||
@click:append="showPass = !showPass"
|
||||
required
|
||||
outlined
|
||||
dense
|
||||
dark
|
||||
filled
|
||||
:type="showPass ? 'text' : 'password'"
|
||||
></v-text-field>
|
||||
</validation-provider>
|
||||
<div class="text-center">
|
||||
<v-btn class="signin-btn" type="submit" rounded color="white">
|
||||
Sign In
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-form>
|
||||
</validation-observer>
|
||||
</v-col>
|
||||
<v-spacer />
|
||||
</v-row>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { required } from "vee-validate/dist/rules";
|
||||
import {
|
||||
extend,
|
||||
ValidationProvider,
|
||||
setInteractionMode,
|
||||
ValidationObserver,
|
||||
} from "vee-validate";
|
||||
|
||||
setInteractionMode("eager");
|
||||
|
||||
extend("required", {
|
||||
...required,
|
||||
message: "{_field_} can not be empty",
|
||||
});
|
||||
|
||||
export default {
|
||||
name: "Login",
|
||||
components: {
|
||||
ValidationProvider,
|
||||
ValidationObserver,
|
||||
},
|
||||
data: () => ({
|
||||
username: "",
|
||||
password: null,
|
||||
showPass: false,
|
||||
response: null,
|
||||
}),
|
||||
computed: {
|
||||
params() {
|
||||
return {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
};
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
async submit() {
|
||||
const valid = await this.$refs.observer.validate();
|
||||
if (valid) {
|
||||
this.login(this.params); // action to login
|
||||
}
|
||||
},
|
||||
async login(payload) {
|
||||
axios
|
||||
.post("http://localhost:8000/api/users/login", payload)
|
||||
.then((response) => {
|
||||
if (response.status == 200) {
|
||||
this.$router.push({ name: "Dashboard" })
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.response.status == 401) {
|
||||
console.log("Bad login info")
|
||||
}
|
||||
})
|
||||
},
|
||||
clear() {
|
||||
// you can use this method to clear login form
|
||||
this.username = "";
|
||||
this.password = null;
|
||||
this.$refs.observer.reset();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Loading…
Reference in new issue