added csrftoken to register REST call

This commit is contained in:
Bachir Soussi Chiadmi 2019-11-06 16:35:15 +01:00
parent eb6cb2db27
commit 55bb48c750
2 changed files with 23 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,7 @@ export default {
// username: '',
mail:'',
token: null,
csrftoken: null,
logout_token: null,
isloggedin: false,
isAdmin: false,
@ -24,6 +25,9 @@ export default {
// mutations
mutations : {
SetCsrftoken (state, token) {
state.csrftoken = token
},
setToken (state, data) {
state.uid = data.current_user.uid
// state.username = data.username
@ -78,17 +82,25 @@ export default {
actions : {
userRegister({ dispatch, commit, state }, credentials){
return new Promise((resolve, reject) => {
REST.post('/user/register?_format=json', credentials)
.then(({ data }) => {
console.log('user REST registered', data);
dispatch('userLogin', credentials)
.then(() => {
resolve()
REST.get('/session/token')
.then(({token}) => {
commit('SetCsrftoken', token)
REST.post('/user/register?_format=json',
credentials,
{'X-CSRF-Token':state.csrftoken}
)
.then(({ data }) => {
console.log('user REST registered', data);
dispatch('userLogin', credentials)
.then(() => {
resolve()
})
})
})
.catch(( error ) => {
console.warn('Issue with register', error)
Promise.reject(error)
.catch(( error ) => {
console.warn('Issue with register', error)
Promise.reject(error)
})
})
})
},