integrated captcha

This commit is contained in:
Massimiliano Assante 2021-11-03 12:57:27 +01:00
parent 1d2533ea3d
commit 9d692c450a
5 changed files with 92 additions and 80 deletions

View File

@ -158,8 +158,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>

View File

@ -5,17 +5,21 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import org.gcube.common.portal.PortalContext;
import com.liferay.portal.kernel.captcha.CaptchaUtil;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
@ -49,9 +53,27 @@ public class CompileForm extends MVCPortlet {
}
super.render(renderRequest, renderResponse);
}
public void addEntry(ActionRequest request, ActionResponse response) {
System.out.println("bao");
public void submittedForm(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String name = actionRequest.getParameter("name");
String surname = actionRequest.getParameter("surname");
String organisation = actionRequest.getParameter("organisation");
String emailAddress = actionRequest.getParameter("emailAddress");
String organisationType = actionRequest.getParameter("organisationType");
String mainMotivation = actionRequest.getParameter("mainMotivation");
String[] itemsAreaOfExpertiseSelectValues = actionRequest.getParameterValues("areaOfExpertiseSelect");
String commitment = actionRequest.getParameter("commitment");
System.out.println("name:" + name);
System.out.println("surname:" + surname);
System.out.println("organisation:" + organisation);
System.out.println("email:" + emailAddress);
System.out.println(organisationType);
System.out.println(mainMotivation);
for (int i = 0; i < itemsAreaOfExpertiseSelectValues.length; i++) {
System.out.println(itemsAreaOfExpertiseSelectValues[i]);
}
System.out.println(commitment);
}
private static List<String> getOrganisationTypes(Connection conn) throws Exception {
@ -95,7 +117,7 @@ public class CompileForm extends MVCPortlet {
}
return toReturn;
}
private static List<String> getDgreesOfParticipation(Connection conn) throws Exception {
_log.debug("getting degrees_of_participation ");
List<String> toReturn = new ArrayList<>();
@ -109,4 +131,6 @@ public class CompileForm extends MVCPortlet {
}
return toReturn;
}
}

View File

@ -6,7 +6,6 @@
<portlet-name>moving-form-compile</portlet-name>
<icon>/icon.png</icon>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portal-javascript>https://www.google.com/recaptcha/api.js</header-portal-javascript>
<footer-portlet-javascript>
/js/main.js
</footer-portlet-javascript>

View File

@ -12,31 +12,41 @@ pageContext.setAttribute("organisation_types", organisation_types);
pageContext.setAttribute("main_motivations", main_motivations);
pageContext.setAttribute("areas_of_expertise", areas_of_expertise);
pageContext.setAttribute("degrees_of_participation", degrees_of_participation);
%>
pageContext.setAttribute("required", "false");
%>
<portlet:defineObjects />
<portlet:actionURL name="addEntry" var="addEntryURL" />
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- This URL validate the CAPTCHA data entered by user -->
<portlet:actionURL var="validateURL" name="submittedForm" />
<p class="lead">Expression of Interest for the EU Multi-Actor
Platform</p>
<aui:form action="<%=addEntryURL%>" method="post" name="movingForm">
<aui:form action="<%=validateURL%>" method="post" name="fm" id="movingForm">
<aui:fieldset>
<aui:input label="Name" name="name" type="text" required="true"
style="width:300px;" />
<aui:input label="Surname" name="surname" type="text" required="true"
<aui:input label="Name" name="name" type="text" required="${required}"
style="width:300px;" />
<aui:input label="Surname" name="surname" type="text"
required="${required}" style="width:300px;" />
<aui:input label="Organisation" name="organisation" type="text"
required="true" style="width:300px;" />
required="${required}" style="width:300px;" />
<aui:select label="Organisation Type" name="organisationType"
required="true" showEmptyOption="true" style="width:800px;">
required="${required}" showEmptyOption="${required}"
style="width:800px;">
<c:forEach var="type" items="${organisation_types}">
<aui:option value="${type}">${type}</aui:option>
</c:forEach>
</aui:select>
<aui:input name="emailAddress" required="true" style="width:300px;">
<aui:input name="emailAddress" required="${required}"
style="width:300px;">
<aui:validator name="email" />
</aui:input>
<aui:input label="Country" name="country" type="text" required="true"
style="width:300px;" />
<aui:input label="Country" name="country" type="text"
required="${required}" style="width:300px;" />
</aui:fieldset>
<aui:fieldset>
<aui:input id="participatedInActivities " type="checkbox"
@ -47,7 +57,7 @@ pageContext.setAttribute("degrees_of_participation", degrees_of_participation);
-->
<aui:select
label="What is your main motivation for joining the EU MAP of MOVING?"
name="mainMotivation" required="true" showEmptyOption="true"
name="mainMotivation" required="${required}" showEmptyOption="true"
style="width:800px;">
<c:forEach var="type" items="${main_motivations}">
<aui:option value="${type}">${type}</aui:option>
@ -62,8 +72,8 @@ pageContext.setAttribute("degrees_of_participation", degrees_of_participation);
-->
<aui:select
label="What is your main area of expertise in relation to mountain sustainability and resilience?"
name="areaOfExpertiseSelect" required="true" style="width:800px;"
multiple="true">
name="areaOfExpertiseSelect" required="${required}"
style="width:800px;" multiple="${required}">
<c:forEach var="type" items="${areas_of_expertise}">
<aui:option value="${type}">${type}</aui:option>
</c:forEach>
@ -73,9 +83,12 @@ pageContext.setAttribute("degrees_of_participation", degrees_of_participation);
label="Please elaborate on the relevant experience you can bring to mountain value chains and the resilience of these areas, so that we have more detailed information to be able to form a dynamic and relevant community."
name="textareaExperience" type="textarea" style="width:800px;"
placeholder="Free text 150 words" />
<!--
SELECT
-->
<aui:select
label="As a starting point, the degree of participation you commit to is:"
name="commitment" required="true" showEmptyOption="true"
name="commitment" required="${required}" showEmptyOption="true"
style="width:800px;">
<c:forEach var="type" items="${degrees_of_participation}">
<aui:option value="${type}">${type}</aui:option>
@ -96,16 +109,37 @@ pageContext.setAttribute("degrees_of_participation", degrees_of_participation);
.
</p>
<aui:input id="privacyPolicyAgree" type="checkbox"
name="privacyPolicyAgree" label="I Agree" required="true" />
name="privacyPolicyAgree" label="I Agree" required="${required}" />
</aui:fieldset>
<!--
Submit Button
-->
<div style="width: 100%; text-align: center;">
<div class="g-recaptcha"
data-sitekey="6Ld0hfYZAAAAAKlIHde1v3QE4NyY4AniN6j-U9SP"></div>
<br />
<aui:button value="Submit your application" type="submit"
cssClass="btn-large btn-fill" />
<div class="g-recaptcha" data-sitekey="6Ld0hfYZAAAAAKlIHde1v3QE4NyY4AniN6j-U9SP"></div>
<br/>
<aui:button-row>
<aui:button value="Submit your application" type="submit"
cssClass="btn-large btn-fill" />
</aui:button-row>
</div>
</aui:form>
<script type="text/javascript">
AUI().use(
'aui-tooltip', 'aui-base', 'selector-css3',
function (A) {
var form = A.one('#<portlet:namespace />fm');
if (form) {
form.on(
'submit',
function(event) {
if (grecaptcha.getResponse() === '') {
event.halt();
event.stopImmediatePropagation();
alert('Please prove you are not a robot');
}
}
);
}
});
</script>

View File

@ -1,60 +1,15 @@
<%@page import="com.liferay.portal.model.Layout"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@page import="com.liferay.util.portlet.PortletRequestUtil"%>
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@ page import="com.liferay.portal.kernel.util.StringUtil" %>
<%@ page import="com.liferay.portal.kernel.util.Validator"%>
<%@ page import="com.liferay.portal.kernel.util.StringPool" %>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
<%@ page import="com.liferay.portal.kernel.bean.BeanParamUtil" %>
<%@ page import="com.liferay.portal.kernel.language.LanguageUtil"%>
<%@page import="com.liferay.portal.kernel.util.GetterUtil"%>
<%@ page import="com.liferay.portal.service.permission.PortalPermissionUtil" %>
<%@ page import="com.liferay.portal.service.permission.PortletPermissionUtil" %>
<%@ page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@ page import="com.liferay.portal.kernel.portlet.LiferayPortletMode"%>
<%@ page import="javax.portlet.PortletURL" %>
<%@ page import="java.util.List" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@page import="com.liferay.portal.kernel.dao.search.RowChecker"%>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Collections" %>
<%@page import="java.util.Date"%>
<%@page import="java.util.Base64"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.text.DateFormat"%>
<%@page import="com.liferay.portal.kernel.workflow.WorkflowConstants"%>
<%@page import="com.liferay.portlet.journal.model.JournalArticle"%>
<%@page import="com.liferay.portlet.dynamicdatamapping.model.DDMTemplate"%>
<%@page import="com.liferay.portlet.dynamicdatamapping.model.DDMStructure"%>
<%@page import="com.liferay.portal.security.permission.ActionKeys"%>
<%@page import="javax.portlet.PortletSession"%>
<%@page import="com.liferay.portal.model.Team"%>
<%@page import="com.liferay.portal.model.Group"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%>
<portlet:defineObjects />
<portlet:defineObjects />
<liferay-theme:defineObjects />
<theme:defineObjects />