|
|
@ -2,19 +2,21 @@ |
|
|
|
<div class="w-full sm:max-w-sm sm:mx-auto sm:my-auto p-6 space-y-4 bg-white rounded-lg shadow-md"> |
|
|
|
<div class="text-center font-thin text-4xl py-4">AUTOPLEX</div> |
|
|
|
<div class="font-medium text-center text-xl">Sign in</div> |
|
|
|
<form> |
|
|
|
<form @submit.prevent="login"> |
|
|
|
<div class="space-y-4"> |
|
|
|
<div> |
|
|
|
<text-box label="Email" type="email" placeholder="john@example.com" :error-message="errors.email"/> |
|
|
|
<text-box label="Email" type="email" ref="email" placeholder="john@example.com" :disabled="isSubmitting" |
|
|
|
v-model="fields.email"/> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
<text-box label="Password" type="password" placeholder="············" :error-message="errors.password"/> |
|
|
|
<text-box label="Password" type="password" ref="password" placeholder="············" :disabled="isSubmitting" |
|
|
|
v-model="fields.password"/> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
<check-box label="Remember Me"/> |
|
|
|
<check-box label="Remember Me" :disabled="isSubmitting"/> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
<button @click="login" class="block w-full rounded-full bg-indigo-500 text-white p-2 focus:outline-none">Sign In</button> |
|
|
|
<button @click="login" :disabled="isSubmitting" class="block w-full rounded-full bg-indigo-500 text-white p-2 focus:outline-none">Sign In</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</form> |
|
|
@ -33,7 +35,8 @@ export default defineComponent({ |
|
|
|
}, |
|
|
|
data() { |
|
|
|
return { |
|
|
|
errors: { |
|
|
|
isSubmitting: false, |
|
|
|
fields: { |
|
|
|
email: "", |
|
|
|
password: "" |
|
|
|
} |
|
|
@ -41,7 +44,37 @@ export default defineComponent({ |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
login() { |
|
|
|
|
|
|
|
if (this.isSubmitting) { |
|
|
|
return; |
|
|
|
} |
|
|
|
this.isSubmitting = true; |
|
|
|
fetch("/auth/login", { |
|
|
|
method: "post", |
|
|
|
headers: { |
|
|
|
"Content-Type": "application/json" |
|
|
|
}, |
|
|
|
body: JSON.stringify(this.fields) |
|
|
|
}) |
|
|
|
.then(async response => { |
|
|
|
this.isSubmitting = false; |
|
|
|
let body = await response.json(); |
|
|
|
console.log("The response is:", response.status); |
|
|
|
if (response.status !== 200) { |
|
|
|
if (body.errors) { |
|
|
|
for (let fieldName in this.fields) { |
|
|
|
let field = <any>this.$refs[fieldName]; |
|
|
|
let message = <string>(body.errors[fieldName] ?? [""])[0]; |
|
|
|
field.setErrorMessage(message); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
this.$router.push({ name: "Login" }); |
|
|
|
}) |
|
|
|
.catch(e => { |
|
|
|
console.error("Error occurred during submission:", e); |
|
|
|
this.isSubmitting = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|