Newer
Older
<div v-if="isLoading">
<div class="sm:block border border-gray-300 rounded-lg mt-6 w-1/3">
<h1
class="
font-bold
text-left
font-montserrat
text-3xl
sm:text-5xl
mb-7
"
>
<div class="my-4" :class="{ invalid: !email.isValid }">
<h1
class="
text-left
font-bold
mb-2
text-xl
sm:text-2xl
font-montserrat
"
>
v-model.trim="email.val"
class="
outline-none
bg-transparent
border border-gray-400
px-4
py-5
rounded-lg
w-full
hover:border-blue-700
focus:border-blue-700
"
placeholder="Enter email."
@blur="clearValidity('email')"
/>
<p v-if="!email.isValid" class="text-red-500">
Email must not be empty.
</p>
<div class="my-4" :class="{ invalid: !password.isValid }">
<h1
class="
text-left
font-bold
mb-2
text-xl
sm:text-2xl
font-montserrat
"
>
v-model.trim="password.val"
class="
text-xl
outline-none
bg-transparent
border border-gray-400
px-4
py-5
rounded-lg
w-full
hover:border-blue-700
focus:border-blue-700
"
placeholder="Enter password."
@blur="clearValidity('password')"
/>
<p v-if="!password.isValid" class="text-red-500">
Password must not be empty.
</p>
<p v-show="error" class="text-red-500">
{{ errorMsg }}
</p>
class="
bg-blue-500
my-4
text-2xl
w-full
font-bold
rounded-lg
p-5
text-white
"
<p class="my-2 font-bold">
<router-link
class="
text-blue-500 text-2xl
hover:text-blue-600 hover:no-underline
"
to="/forgotpassword"
>
<h4>
Don't have an account yet?
<router-link
class="
text-blue-500 text-2xl
font-bold
hover:text-blue-600 hover:no-underline
"
to="/signup"
>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
let host = require("@/components/js/const").apiHost;
name: "Login",
email: {
val: "",
isValid: true,
},
password: {
val: "",
isValid: true,
},
formIsValid: true,
errorMsg: ``,
isDev: process.env.NODE_ENV === "development",
isLoading: false,
};
computed: {
userData: function () {
return this.$store.getters["User/userData"];
const vm = this;
if (vm.userData !== null) {
this.$router.push("/profile");
clearValidity(input) {
this[input].isValid = true;
},
validateForm() {
this.formIsValid = true;
if (this.email.val === "") {
this.email.isValid = false;
this.formIsValid = false;
}
if (this.password.val === "") {
this.password.isValid = false;
this.formIsValid = false;
}
},
e.preventDefault();
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
vm.validateForm();
if (!vm.formIsValid) {
return;
}
if (vm.isDev) {
host = require("@/components/js/const").devApiHost;
}
this.isLoading = true;
const res = await fetch(`${host}/api/auth/local`, {
method: "POST",
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache,
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
identifier: this.email.val,
password: this.password.val,
}),
});
if (!res.ok && res.status === 500) {
this.isLoading = false;
this.error = true;
this.errorMsg = `${res.status} Internal Error, please write a mail to DDCode Admin`;
if (!res.ok && res.status === 405) {
this.isLoading = false;
this.error = true;
this.errorMsg = `${res.status} Internal Error, please write a mail to DDCode Admin`;
return;
}
const response = await res.json();
if (!res.ok && response.error.status === 400 && response.error.message === "Invalid identifier or password") {
this.isLoading = false;
this.error = true;
this.errorMsg = "Email Address & Password mismatch.";
this.password.val = "";
return;
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
const { jwt, user } = response;
window.localStorage.setItem("jwt", jwt);
window.localStorage.setItem("userData", JSON.stringify(user));
this.$store.dispatch("User/setJwt", jwt);
this.$store.dispatch("User/setUserData", user);
this.isLoading = false;
this.error = false;
this.$router.push("/profile");
// const res = await this.axios.post(`${host}/api/auth/local`, {
// identifier: this.email.val,
// password: this.password.val
// });
// console.log("error is ", res);
// const { jwt, user } = res.data
// console.log(user)
// window.localStorage.setItem('jwt', jwt)
// window.localStorage.setItem('userData', JSON.stringify(user))
// this.$store.dispatch('User/setJwt', jwt)
// this.$store.dispatch('User/setUserData', user)
// this.isLoading= false;
// this.error= false;
// this.$router.push('/profile')
// console.log(error.response.data.error.message)
// console.log("error",e.data);
// this.isLoading= false;
// this.error = true
// this.password.val = ''
// this.isLoading= false
},
};
@import url("~@/assets/bootstrap.css");
a {
color: #42b983;
}
.invalid h1 {
color: red;
}
.invalid input {
border: 1px solid red;
}