/
Login.vue
81 lines (78 loc) · 1.98 KB
/
Login.vue
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
<template>
<v-layout class="background mt-5">
<div style="margin: 130px auto">
<v-card max-width="400" flat>
<v-card-title class="justify-center">
<h2>Login</h2>
</v-card-title>
<div class="mr-5 ml-5" />
<v-card-text>
<v-form ref="form" class="px-3">
<v-text-field
v-model="username"
outlined
label="username"
:prepend-icon="mdiAccount"
:rules="inputRules"
autocomplete="current email"
name="username"
@keyup.enter.native="Login"
/>
<v-text-field
v-model="password"
outlined
type="password"
label="password"
:prepend-icon="mdiLock"
:rules="inputRules"
autocomplete="current password"
name="password"
@keyup.enter.native="Login"
/>
<v-spacer />
<v-card-actions class="justify-center">
<v-btn
text
class="accent white--text mx-0 mt-3"
@click="Login"
>
Login
</v-btn>
</v-card-actions>
</v-form>
</v-card-text>
</v-card>
</div>
</v-layout>
</template>
<script>
import { mdiLock, mdiAccount } from '@mdi/js'
import { isAuthenticated } from '@/services/auth.js'
export default {
name: 'Login',
data() {
return {
username: '',
password: '',
inputRules: [v => v.length >= 1 || 'At least 1 character'],
mdiLock, mdiAccount
}
},
mounted() {
if (isAuthenticated()) {
this.$router.push('/')
}
},
methods: {
async Login() {
const authenticated = await this.$store.dispatch('LOGIN', {
username: this.username,
password: this.password
})
if (authenticated) {
this.$router.push('/')
}
}
}
}
</script>