Browse Source

alpha tested reCAPTCHA v2.

master
Massimiliano Assante 8 months ago
parent
commit
e99dc24172
  1. 27
      src/main/java/org/gcube/portlets/user/MailForm.java
  2. 7
      src/main/webapp/html/mailform/view.jsp

27
src/main/java/org/gcube/portlets/user/MailForm.java

@ -26,8 +26,7 @@ import javax.mail.internet.InternetAddress;
*/
public class MailForm extends MVCPortlet {
@ProcessAction(name = "validateCaptcha")
public void validateCaptcha(ActionRequest actionRequest,
public void submitSuggestion(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String name = ParamUtil.getString(actionRequest, "name");
@ -49,16 +48,6 @@ public class MailForm extends MVCPortlet {
if (splits.length > 1)
emailAddress = "info@"+ hostname.split("www.")[1];
}
try {
/**
* This is the actual code which validate captcha data entered by user.
*/
CaptchaUtil.check(actionRequest);
System.out.println("CAPTCHA validated successfully");
} catch (CaptchaException e) {
e.printStackTrace();
SessionErrors.add(actionRequest, "errorMessage");
}
String bodyTextHTML = "<p>From: " + name + "</p>";
bodyTextHTML += "<p>Email: " + email + "</p>";
bodyTextHTML += "<p>Message:</p><p> " + message + "</p>";
@ -83,19 +72,5 @@ public class MailForm extends MVCPortlet {
return result;
}
/**
* The below code is responsible for rendering the CAPTCHA image
*/
@Override
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws IOException,
PortletException {
try {
CaptchaUtil.serveImage(resourceRequest, resourceResponse);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

7
src/main/webapp/html/mailform/view.jsp

@ -1,13 +1,8 @@
<%@ include file="init.jsp"%>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- This URL will be invoked before showing the CAPTCHA image -->
<portlet:resourceURL var="captchaURL" />
<!-- This URL validate the CAPTCHA data entered by user -->
<portlet:actionURL var="validateURL" name="validateCaptcha" />
<liferay-ui:error key="errorMessage"
message="Enter correct data as shown in the image" />
<portlet:actionURL var="validateURL" name="submitSuggestion" />
<aui:form action="<%=validateURL%>" method="post" name="fm">

Loading…
Cancel
Save