removed crappy test login files

This commit is contained in:
Tobias Kurze
2019-03-22 16:38:09 +01:00
parent 102db7ae0c
commit 1ee42cb01b
17 changed files with 86 additions and 769 deletions

View File

@@ -3,8 +3,8 @@ import Vuex from 'vuex';
// imports of AJAX functions will go here
import { fetchSurveys, fetchSurvey, saveSurveyResponse, postNewSurvey, authenticate, register } from '@/api'
import { isValidJwt, EventBus } from '@/utils'
import { fetchSurveys, fetchSurvey, saveSurveyResponse, postNewSurvey, authenticate, register } from '@/api';
import { isValidJwt, EventBus } from '@/utils';
Vue.use(Vuex);
@@ -13,98 +13,96 @@ const state = {
surveys: [],
currentSurvey: {},
user: {},
jwt: ''
}
jwt: '',
};
const actions = {
// asynchronous operations
loadSurveys (context: any) {
loadSurveys(context: any) {
return fetchSurveys()
.then((response) => {
context.commit('setSurveys', { surveys: response.data })
})
context.commit('setSurveys', { surveys: response.data });
});
},
// @ts-ignore
loadSurvey (context: any, { id }) {
loadSurvey(context: any, { id }) {
return fetchSurvey(id)
.then((response) => {
context.commit('setSurvey', { survey: response.data })
})
context.commit('setSurvey', { survey: response.data });
});
},
addSurveyResponse (context: any) {
return saveSurveyResponse(context.state.currentSurvey)
addSurveyResponse(context: any) {
return saveSurveyResponse(context.state.currentSurvey);
},
login (context: any, userData: any) {
context.commit('setUserData', { userData })
login(context: any, userData: any) {
context.commit('setUserData', { userData });
return authenticate(userData)
.then(response => context.commit('setJwtToken', { jwt: response.data }))
.catch(error => {
console.log('Error Authenticating: ', error)
// @ts-ignore
EventBus.emit('failedAuthentication', error)
})
.then((response) => context.commit('setJwtToken', { jwt: response.data }))
.catch((error) => {
console.log('Error Authenticating: ', error);
EventBus.$emit('failedAuthentication', error);
});
},
register (context: any, userData: any) {
context.commit('setUserData', { userData })
register(context: any, userData: any) {
context.commit('setUserData', { userData });
return register(userData)
.then(context.dispatch('login', userData))
.catch(error => {
console.log('Error Registering: ', error)
// @ts-ignore
EventBus.emit('failedRegistering: ', error)
})
.catch((error) => {
console.log('Error Registering: ', error);
EventBus.$emit('failedRegistering: ', error);
});
},
submitNewSurvey (context: any, survey: any) {
return postNewSurvey(survey, context.state.jwt.token)
}
}
submitNewSurvey(context: any, survey: any) {
return postNewSurvey(survey, context.state.jwt.token);
},
};
const mutations = {
// isolated data mutations
setSurveys (state: any, payload: any) {
state.surveys = payload.surveys
setSurveys(sState: any, payload: any) {
sState.surveys = payload.surveys;
},
setSurvey (state: any, payload: any) {
const nQuestions = payload.survey.questions.length
setSurvey(sState: any, payload: any) {
const nQuestions = payload.survey.questions.length;
for (let i = 0; i < nQuestions; i++) {
payload.survey.questions[i].choice = null
payload.survey.questions[i].choice = null;
}
state.currentSurvey = payload.survey
sState.currentSurvey = payload.survey;
},
setChoice (state: any, payload: any) {
const { questionId, choice } = payload
const nQuestions = state.currentSurvey.questions.length
setChoice(sState: any, payload: any) {
const { questionId, choice } = payload;
const nQuestions = sState.currentSurvey.questions.length;
for (let i = 0; i < nQuestions; i++) {
if (state.currentSurvey.questions[i].id === questionId) {
state.currentSurvey.questions[i].choice = choice
break
if (sState.currentSurvey.questions[i].id === questionId) {
sState.currentSurvey.questions[i].choice = choice;
break;
}
}
},
setUserData (state: any, payload: any) {
console.log('setUserData payload = ', payload)
state.userData = payload.userData
setUserData(sState: any, payload: any) {
console.log('setUserData payload = ', payload);
sState.userData = payload.userData;
},
setJwtToken (state: any, payload: any) {
console.log('setJwtToken payload = ', payload)
localStorage.token = payload.jwt.token
state.jwt = payload.jwt
}
}
setJwtToken(sState: any, payload: any) {
console.log('setJwtToken payload = ', payload);
localStorage.token = payload.jwt.token;
sState.jwt = payload.jwt;
},
};
const getters = {
// reusable data accessors
isAuthenticated (state: any) {
return isValidJwt(state.jwt.token)
}
}
isAuthenticated(sState: any) {
return isValidJwt(sState.jwt.token);
},
};
const store = new Vuex.Store({
state,
actions,
mutations,
getters
})
getters,
});
export default store
export default store;