Fix captcha error list

This commit is contained in:
Paulo Gustavo Veiga 2022-02-12 07:52:16 -08:00
parent ea1349c518
commit 9af7247072
3 changed files with 11 additions and 28 deletions

View File

@ -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;
@ -53,7 +54,12 @@ public class RecaptchaService {
final Boolean success = (Boolean) responseBody.get("success");
if (success != null && !success) {
final List<String> errorCodes = (List<String>) 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);
@ -69,29 +75,3 @@ public class RecaptchaService {
this.recaptchaSecret = recaptchaSecret;
}
}
class RecaptchaUtil {
private static final Map<String, String>
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.");
}
}

View File

@ -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";
}

View File

@ -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."