mirror of https://github.com/doccano/doccano.git
pythonannotation-tooldatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learning
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
71 lines
1.6 KiB
export const state = () => ({
|
|
username: null,
|
|
id: null,
|
|
isAuthenticated: false,
|
|
isStaff: false
|
|
})
|
|
|
|
export const mutations = {
|
|
setUsername(state, username) {
|
|
state.username = username
|
|
},
|
|
setUserId(state, userId) {
|
|
state.id = userId
|
|
},
|
|
clearUsername(state) {
|
|
state.username = null
|
|
},
|
|
setAuthenticated(state, isAuthenticated) {
|
|
state.isAuthenticated = isAuthenticated
|
|
},
|
|
setIsStaff(state, isStaff) {
|
|
state.isStaff = isStaff
|
|
}
|
|
}
|
|
|
|
export const getters = {
|
|
isAuthenticated(state) {
|
|
return state.isAuthenticated
|
|
},
|
|
getUsername(state) {
|
|
return state.username
|
|
},
|
|
getUserId(state) {
|
|
return state.id
|
|
},
|
|
isStaff(state) {
|
|
return state.isStaff
|
|
}
|
|
}
|
|
|
|
export const actions = {
|
|
async authenticateUser({ commit }, authData) {
|
|
try {
|
|
await this.$repositories.auth.login(authData.username, authData.password)
|
|
commit('setAuthenticated', true)
|
|
} catch (error) {
|
|
throw new Error('The credential is invalid')
|
|
}
|
|
},
|
|
async fetchSocialLink() {
|
|
return await this.$repositories.auth.socialLink()
|
|
},
|
|
async initAuth({ commit }) {
|
|
try {
|
|
const user = await this.$repositories.user.getProfile()
|
|
commit('setAuthenticated', true)
|
|
commit('setUsername', user.username)
|
|
commit('setUserId', user.id)
|
|
commit('setIsStaff', user.isStaff)
|
|
} catch {
|
|
commit('setAuthenticated', false)
|
|
commit('setIsStaff', false)
|
|
}
|
|
},
|
|
async logout({ commit }) {
|
|
await this.$repositories.auth.logout()
|
|
commit('setAuthenticated', false)
|
|
commit('setIsStaff', false)
|
|
commit('clearUsername')
|
|
}
|
|
}
|