added csrftoken to register REST call
This commit is contained in:
parent
eb6cb2db27
commit
55bb48c750
File diff suppressed because one or more lines are too long
|
@ -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)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue