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.
68 lines
1.5 KiB
68 lines
1.5 KiB
import requestAction from 'Utilities/requestAction';
|
|
import * as types from './actionTypes';
|
|
import { setCaptchaValue } from './captchaActions';
|
|
|
|
const captchaActionHandlers = {
|
|
[types.REFRESH_CAPTCHA]: function(payload) {
|
|
return (dispatch, getState) => {
|
|
const actionPayload = {
|
|
action: 'checkCaptcha',
|
|
...payload
|
|
};
|
|
|
|
dispatch(setCaptchaValue({
|
|
refreshing: true
|
|
}));
|
|
|
|
const promise = requestAction(actionPayload);
|
|
|
|
promise.done((data) => {
|
|
if (!data.captchaRequest) {
|
|
dispatch(setCaptchaValue({
|
|
refreshing: false
|
|
}));
|
|
}
|
|
|
|
dispatch(setCaptchaValue({
|
|
refreshing: false,
|
|
...data.captchaRequest
|
|
}));
|
|
});
|
|
|
|
promise.fail(() => {
|
|
dispatch(setCaptchaValue({
|
|
refreshing: false
|
|
}));
|
|
});
|
|
};
|
|
},
|
|
|
|
[types.GET_CAPTCHA_COOKIE]: function(payload) {
|
|
return (dispatch, getState) => {
|
|
const state = getState().captcha;
|
|
|
|
const queryParams = {
|
|
responseUrl: state.responseUrl,
|
|
ray: state.ray,
|
|
captchaResponse: payload.captchaResponse
|
|
};
|
|
|
|
const actionPayload = {
|
|
action: 'getCaptchaCookie',
|
|
queryParams,
|
|
...payload
|
|
};
|
|
|
|
const promise = requestAction(actionPayload);
|
|
|
|
promise.done((data) => {
|
|
dispatch(setCaptchaValue({
|
|
token: data.captchaToken
|
|
}));
|
|
});
|
|
};
|
|
}
|
|
};
|
|
|
|
export default captchaActionHandlers;
|