123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import { HTTP } from 'vuejs/rest/http-axios'
- import qs from 'querystring'
- export default {
- namespaced: true,
- // initial state
- state : {
- uid:null,
- // username: '',
- mail:'',
- token: null,
- logout_token: null
- // isloggedin: false
- },
- // getters
- getters : {},
- // mutations
- mutations : {
- setUser (state, data) {
- state.uid = data.current_user.uid
- // state.username = data.username
- state.mail = data.current_user.mail
- state.token = data.csrf_token
- state.logout_token = data.logout_token
- },
- setLoggedOut (state) {
- state.uid= null
- state.mail = ''
- state.token = null
- state.logout_token = null
- }
- },
- // actions
- actions : {
- getToken ({ commit, state }, credentials) {
- HTTP.post('/user/login?_format=json', credentials)
- .then(({ data }) => {
- console.log('data', data)
- commit('setUser', data)
- })
- .catch(( error ) => {
- console.log('Issue with login', error)
- Promise.reject(error)
- })
- },
- userLogout ({ commit, state }) {
- let credentials = qs.stringify({
- token: state.token
- })
- HTTP.post('/user/logout', credentials)
- .then((resp) => {
- console.log('resp', resp)
- commit('setLoggedOut')
- })
- .catch(( error ) => {
- console.log('Issue with logout', error)
- Promise.reject(error)
- })
- }
- }
- }
|