login form, actions, and mutations
This commit is contained in:
@@ -69,6 +69,8 @@
|
|||||||
@import '~bulma/sass/components/nav'
|
@import '~bulma/sass/components/nav'
|
||||||
@import '~bulma/sass/components/card'
|
@import '~bulma/sass/components/card'
|
||||||
@import '~bulma/sass/elements/button'
|
@import '~bulma/sass/elements/button'
|
||||||
|
@import '~bulma/sass/elements/form'
|
||||||
|
@import '~bulma/sass/elements/icon'
|
||||||
@import '~bulma/sass/elements/other'
|
@import '~bulma/sass/elements/other'
|
||||||
@import '~bulma/sass/grid/columns'
|
@import '~bulma/sass/grid/columns'
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,35 @@
|
|||||||
|
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="notification">
|
<form @submit.prevent="doLogin">
|
||||||
Login Here...
|
|
||||||
</div>
|
<label class="label">Email</label>
|
||||||
<div class="notification">
|
<p class="control has-icon has-icon-left">
|
||||||
{{ redirect }}
|
<input class="input" type="email" placeholder="Email" v-model="email">
|
||||||
</div>
|
<span class="icon is-small">
|
||||||
|
<i class="fa fa-envelope-open-o"></i>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<label class="label">Password</label>
|
||||||
|
<p class="control has-addons has-icon has-icon-left">
|
||||||
|
<input class="input is-expanded" type="password" placeholder="password" v-model="password">
|
||||||
|
<span class="icon is-small">
|
||||||
|
<i class="fa fa-key"></i>
|
||||||
|
</span>
|
||||||
|
<button type="" class="button is-primary">
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapGetters } from 'vuex';
|
||||||
import TopNav from '../components/TopNav.vue';
|
import TopNav from '../components/TopNav.vue';
|
||||||
import store from '../store'
|
import store from '../store'
|
||||||
|
|
||||||
@@ -35,15 +52,20 @@
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
sendTo: {},
|
sendTo: {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
methods: {
|
||||||
redirect: function() {
|
doLogin() {
|
||||||
return Object.keys(this.sendTo).reduce((str, val) => {
|
const { email, password } = this;
|
||||||
return str += `${val}: ${this.sendTo[val]}; `;
|
|
||||||
}, 'REDIRECT: ');
|
store.dispatch('userLogin', { email, password })
|
||||||
},
|
.then(() => {
|
||||||
|
this.$router.push(this.sendTo);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
const getRedirect = (query) => {
|
const getRedirect = (query) => {
|
||||||
|
|||||||
@@ -2,8 +2,40 @@ export default {
|
|||||||
state: {
|
state: {
|
||||||
user: null,
|
user: null,
|
||||||
},
|
},
|
||||||
|
mutations: {
|
||||||
|
setUser(state, user) {
|
||||||
|
state.user = user;
|
||||||
|
},
|
||||||
|
resetUser(state) {
|
||||||
|
state.user = null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
userLogin({ commit }, user = {}) {
|
||||||
|
const { email, password } = user;
|
||||||
|
|
||||||
|
// TODO: login via the server
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!email || !password) {
|
||||||
|
commit('resetUser');
|
||||||
|
reject();
|
||||||
|
} else {
|
||||||
|
commit('setUser', email);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
userLogout({ commit }) {
|
||||||
|
// TODO: logout via the server
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
commit('resetUser');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
getters: {
|
getters: {
|
||||||
isAuthenticated(state) {
|
isAuthenticated(state) {
|
||||||
|
// TODO: real user data checking via the server
|
||||||
return state.user !== null;
|
return state.user !== null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user