From a525df32c9bbba873ecca2939b013985c51d27bc Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 16 Dec 2018 20:53:41 +0300 Subject: [PATCH] Separate captcha into the backendInteractor --- src/components/registration/registration.js | 9 ++------- src/modules/users.js | 4 ++++ src/services/api/api.service.js | 3 +++ .../backend_interactor_service.js | 2 ++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js index c4e96b3c..7a742b3d 100644 --- a/src/components/registration/registration.js +++ b/src/components/registration/registration.js @@ -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 diff --git a/src/modules/users.js b/src/modules/users.js index 25d1c81f..65b172bc 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -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) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index ae876b7f..b509c905 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -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, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index c84373ac..cc72f607 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -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,