From 9af7247072c626ccfe8567273de2061a62efc451 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 12 Feb 2022 07:52:16 -0800 Subject: [PATCH] Fix captcha error list --- .../wisemapping/service/RecaptchaService.java | 36 +++++-------------- .../com/wisemapping/validator/Messages.java | 2 ++ .../src/main/resources/messages_en.properties | 1 + 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java b/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java index 041a5384..d50e35e0 100644 --- a/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/RecaptchaService.java @@ -1,6 +1,7 @@ package com.wisemapping.service; import com.fasterxml.jackson.databind.ObjectMapper; +import com.wisemapping.validator.Messages; import org.apache.commons.lang.StringUtils; import org.apache.http.NameValuePair; import org.apache.http.client.fluent.Form; @@ -51,9 +52,14 @@ public class RecaptchaService { logger.warn("Response from recaptcha after parse: " + responseBody); final Boolean success = (Boolean) responseBody.get("success"); - if (success!=null && !success) { + if (success != null && !success) { final List errorCodes = (List) responseBody.get("error-codes"); - result = RecaptchaUtil.codeToDescription(errorCodes.get(0)); + if (errorCodes.get(0).equals("timeout-or-duplicate")) { + result = Messages.CAPTCHA_TIMEOUT_OUT_DUPLICATE; + } else { + result = Messages.CAPTCHA_LOADING_ERROR; + logger.error("Unexpected error during catch resolution:" + errorCodes); + } } } catch (IOException e) { logger.error(e.getMessage(), e); @@ -68,30 +74,4 @@ public class RecaptchaService { public void setRecaptchaSecret(String recaptchaSecret) { this.recaptchaSecret = recaptchaSecret; } -} - -class RecaptchaUtil { - - private static final Map - RECAPTCHA_ERROR_CODE = new HashMap<>(); - - static String codeToDescription(final String code) - { - return RECAPTCHA_ERROR_CODE.getOrDefault(code,"Unexpected error validating code. Please, refresh the page and try again."); - } - - static { - RECAPTCHA_ERROR_CODE.put("missing-input-secret", - "The secret parameter is missing"); - RECAPTCHA_ERROR_CODE.put("invalid-input-secret", - "The secret parameter is invalid or malformed"); - RECAPTCHA_ERROR_CODE.put("missing-input-response", - "The response parameter is missing"); - RECAPTCHA_ERROR_CODE.put("invalid-input-response", - "The response parameter is invalid or malformed"); - RECAPTCHA_ERROR_CODE.put("bad-request", - "The request is invalid or malformed"); - RECAPTCHA_ERROR_CODE.put("timeout-or-duplicate", - "Please, refresh the page and try again."); - } } \ No newline at end of file diff --git a/wise-webapp/src/main/java/com/wisemapping/validator/Messages.java b/wise-webapp/src/main/java/com/wisemapping/validator/Messages.java index 043eb172..36aee920 100644 --- a/wise-webapp/src/main/java/com/wisemapping/validator/Messages.java +++ b/wise-webapp/src/main/java/com/wisemapping/validator/Messages.java @@ -26,4 +26,6 @@ public interface Messages { String LABEL_TITLE_ALREADY_EXISTS = "LABEL_TITLE_ALREADY_EXISTS"; String PASSWORD_MISMATCH = "PASSWORD_MISMATCH"; String CAPTCHA_LOADING_ERROR = "CAPTCHA_LOADING_ERROR"; + + String CAPTCHA_TIMEOUT_OUT_DUPLICATE = "CAPTCHA_TIMEOUT_OUT_DUPLICATE"; } diff --git a/wise-webapp/src/main/resources/messages_en.properties b/wise-webapp/src/main/resources/messages_en.properties index 5c38e35c..01a8a88d 100644 --- a/wise-webapp/src/main/resources/messages_en.properties +++ b/wise-webapp/src/main/resources/messages_en.properties @@ -51,3 +51,4 @@ TRY_WELCOME = This edition space showcases some of the mindmap editor capabiliti UNEXPECTED_ERROR_DETAILS = Unexpected error processing request. NO_ENOUGH_PERMISSIONS=This mind map can opened. NO_ENOUGH_PERMISSIONS_DETAILS=You do not have enough right access to see this map. This map has been changed to private or deleted. +CAPTCHA_TIMEOUT_OUT_DUPLICATE="Please, refresh the page and try again." \ No newline at end of file