Separate captcha into the backendInteractor

This commit is contained in:
Ekaterina Vaartis 2018-12-16 20:53:41 +03:00
parent 92de235f4e
commit a525df32c9
4 changed files with 11 additions and 7 deletions

View File

@ -31,12 +31,7 @@ const registration = {
this.$router.push('/main/all')
}
fetch("/api/pleroma/captcha")
.then(resp => resp.json())
.then(resp => {
// TODO: check for errors
this.captcha = resp
})
this.getCaptcha().then(cpt => this.captcha = cpt)
},
computed: {
token () { return this.$route.params.token },
@ -49,7 +44,7 @@ const registration = {
})
},
methods: {
...mapActions(['signUp']),
...mapActions(['signUp', 'getCaptcha']),
async submit () {
this.user.nickname = this.user.username
this.user.token = this.token

View File

@ -142,6 +142,10 @@ const users = {
throw Error(errors)
}
},
async getCaptcha (store) {
return await store.rootState.api.backendInteractor.getCaptcha()
},
logout (store) {
store.commit('clearCurrentUser')
store.commit('setToken', false)

View File

@ -167,6 +167,8 @@ const register = (params) => {
})
}
const getCaptcha = () => fetch('/api/pleroma/captcha').then(resp => resp.json())
const authHeaders = (accessToken) => {
if (accessToken) {
return { 'Authorization': `Bearer ${accessToken}` }
@ -496,6 +498,7 @@ const apiService = {
setUserMute,
fetchMutes,
register,
getCaptcha,
updateAvatar,
updateBg,
updateProfile,

View File

@ -71,6 +71,7 @@ const backendInteractorService = (credentials) => {
const fetchMutes = () => apiService.fetchMutes({credentials})
const fetchFollowRequests = () => apiService.fetchFollowRequests({credentials})
const getCaptcha = () => apiService.getCaptcha()
const register = (params) => apiService.register(params)
const updateAvatar = ({params}) => apiService.updateAvatar({credentials, params})
const updateBg = ({params}) => apiService.updateBg({credentials, params})
@ -100,6 +101,7 @@ const backendInteractorService = (credentials) => {
setUserMute,
fetchMutes,
register,
getCaptcha,
updateAvatar,
updateBg,
updateBanner,