1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<template>
<ion-page>
<m6-header />
<ion-content :fullscreen="true">
<form id="login">
<h2>Sign in</h2>
<ion-item lines="none">
<ion-input
placeholder="username"
type="text"
:value="form.username"
@ionInput="form.username = $event.target.value"
/>
</ion-item>
<ion-item lines="none">
<ion-input
placeholder="password"
type="password"
:value="form.password"
@ionInput="form.password = $event.target.value"
/>
</ion-item>
<ion-button color="primary" id="log" @click="handleLogin()">
Submit
</ion-button>
</form>
</ion-content>
<m6-footer />
</ion-page>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import { IonPage, IonContent } from "@ionic/vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import { mapGetters, mapActions } from "vuex";
export default defineComponent({
name: "Sign",
components: {
IonContent,
IonPage,
"m6-header": Header,
"m6-footer": Footer,
},
data() {
return {
form: { username: "", password: "" },
};
},
computed: {
...mapGetters("auth", ["isLogged"]),
},
created() {
if (this.isLogged) window.location.href = "/me";
},
methods: {
handleLogin() {
if (this.form.username == "" || this.form.password == "") {
this.toast({
header: "All fields are required",
text: "",
color: "danger",
});
return;
}
this.login(this.form).then((response) => {
if (response.status != 200) {
this.toast({
header: response.data.error,
text: "",
color: "danger",
});
} else {
this.toast({
header: "Logged successfully",
text: "",
color: "success",
});
setTimeout(() => {
window.location.href = "/me";
}, 2000);
}
});
},
...mapActions(["toast"]),
...mapActions("auth", ["login"]),
},
});
</script>
|