REST login/logout is working

This commit is contained in:
2019-04-10 10:47:45 +02:00
parent 9dfc5af5c0
commit 3f2568039e
7 changed files with 305 additions and 74 deletions

View File

@ -0,0 +1,72 @@
<template lang="html">
<div id="block-userlogin" class="">
<h2>Login Hello!</h2>
<section>
<input
id="edit-name"
class="form-email"
type="text"
placeholder="Email" name="name"
v-model="mail"
@keyup.enter="login"
/>
<input
id="edit-pass"
class="form-text"
type="password"
placeholder="Password" name="pass"
v-model="password"
@keyup.enter="login"
/>
<button
id="edit-submit"
class="button"
@click.stop="login"
>
login
</button>
</section>
</div>
</template>
<script>
// https://github.com/alvar0hurtad0/drupal-vuejs-todo
import { mapState, mapActions } from 'vuex'
export default {
data () {
return {
mail: '',
password: ''
}
},
computed: {
...mapState(['User'])
},
methods: {
...mapActions({
getToken: 'User/getToken'
}),
// usernameInputHandler(input) {
// this.username = input;
// },
// passwordInputHandler(input) {
// this.password = input;
// },
login () {
this.getToken({
mail: this.mail,
pass: this.password
})
}
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -0,0 +1,31 @@
<template lang="html">
<UserTools v-if="token" />
<Login v-else />
</template>
<script>
import { mapState, mapActions } from 'vuex'
import Login from 'vuejs/components/User/Login'
import UserTools from 'vuejs/components/User/UserTools'
export default {
// data () {
// return {}
// },
computed: {
...mapState({
token: state => state.User.token
})
},
components: {
Login,
UserTools
}
}
</script>
<style lang="css" scoped>
</style>

View File

@ -0,0 +1,38 @@
<template lang="html">
<div id="user-tools">
<h4>{{ mail }}</h4>
<a href="/user/logout"
@click.prevent="onLogout()"
>
logout
</a>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
export default {
// data () {
// return {
// mail: "Hello User!"
// }
// },
computed: {
...mapState({
mail: state => state.User.mail
})
},
methods: {
...mapActions({
userLogout: 'User/userLogout'
}),
onLogout () {
this.userLogout()
}
}
}
</script>
<style lang="css" scoped>
</style>