Commit a634d089f194ae2cee0183bcb8fe8c3b1c8c5c89

Authored by Tiago Guimarães
1 parent d034a06a04
Exists in DSpace52++

Feedback requires recaptcha

dspace-jspui/src/main/java/org/dspace/app/webui/servlet/FeedbackServlet.java
... ... @@ -27,6 +27,7 @@ import org.dspace.core.Email;
27 27 import org.dspace.core.I18nUtil;
28 28 import org.dspace.core.LogManager;
29 29 import org.dspace.eperson.EPerson;
  30 +import pt.uminho.sdum.utils.VerifyRecaptcha;
30 31  
31 32 /**
32 33 * Servlet for handling user feedback
... ... @@ -91,12 +92,18 @@ public class FeedbackServlet extends DSpaceServlet
91 92 // Has the user just posted their feedback?
92 93 if (request.getParameter("submit") != null)
93 94 {
  95 +
  96 + String gRecaptchaResponse = request
  97 + .getParameter("g-recaptcha-response");
  98 + boolean verify = VerifyRecaptcha.verify(gRecaptchaResponse);
  99 +
94 100 EmailValidator ev = EmailValidator.getInstance();
95 101 String feedback = request.getParameter("feedback");
96 102  
97 103 // Check all data is there
98 104 if ((formEmail == null) || formEmail.equals("")
99   - || (feedback == null) || feedback.equals("") || !ev.isValid(formEmail))
  105 + || (feedback == null) || feedback.equals("") || !ev.isValid(formEmail)
  106 + || !verify)
100 107 {
101 108 log.info(LogManager.getHeader(context, "show_feedback_form",
102 109 "problem=true"));
... ...
dspace-jspui/src/main/webapp/feedback/form.jsp
... ... @@ -17,33 +17,31 @@
17 17  
18 18 <%@ page contentType="text/html;charset=UTF-8" %>
19 19 <%@ page import="org.apache.commons.lang.StringEscapeUtils" %>
  20 +<%@ page import="org.dspace.core.ConfigurationManager" %>
20 21 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
21 22 <%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %>
  23 +<script src='https://www.google.com/recaptcha/api.js'></script>
22 24  
23 25 <%
24 26 boolean problem = (request.getParameter("feedback.problem") != null);
25 27 String email = request.getParameter("email");
26 28  
27   - if (email == null || email.equals(""))
28   - {
  29 + if (email == null || email.equals("")) {
29 30 email = (String) request.getAttribute("authenticated.email");
30 31 }
31 32  
32   - if (email == null)
33   - {
  33 + if (email == null) {
34 34 email = "";
35 35 }
36 36  
37 37 String feedback = request.getParameter("feedback");
38   - if (feedback == null)
39   - {
  38 + if (feedback == null) {
40 39 feedback = "";
41 40 }
42 41  
43 42 String fromPage = request.getParameter("fromPage");
44   - if (fromPage == null)
45   - {
46   - fromPage = "";
  43 + if (fromPage == null) {
  44 + fromPage = "";
47 45 }
48 46 %>
49 47  
... ... @@ -55,29 +53,46 @@
55 53 DSpace system. Your comments are appreciated!</p> --%>
56 54 <p><fmt:message key="jsp.feedback.form.text1"/></p>
57 55  
58   -<%
59   - if (problem)
60   - {
61   -%>
62   - <%-- <p><strong>Please fill out all of the information below.</strong></p> --%>
63   - <p><strong><fmt:message key="jsp.feedback.form.text2"/></strong></p>
64   -<%
65   - }
66   -%>
  56 + <%
  57 + if (problem) {
  58 + %>
  59 + <%-- <p><strong>Please fill out all of the information below.</strong></p> --%>
  60 + <p><strong><fmt:message key="jsp.feedback.form.text2"/></strong></p>
  61 + <%
  62 + }
  63 + %>
67 64 <form action="<%= request.getContextPath() %>/feedback" method="post">
68 65 <center>
69 66 <table>
70 67 <tr>
71   - <td class="submitFormLabel"><label for="temail"><fmt:message key="jsp.feedback.form.email"/></label></td>
72   - <td><input type="text" name="email" id="temail" size="50" value="<%=StringEscapeUtils.escapeHtml(email)%>" /></td>
  68 + <td class="submitFormLabel"><label for="temail"><fmt:message key="jsp.feedback.form.email"/></label>
  69 + </td>
  70 + <td><input type="text" name="email" id="temail" size="50"
  71 + value="<%=StringEscapeUtils.escapeHtml(email)%>"/></td>
73 72 </tr>
74 73 <tr>
75   - <td class="submitFormLabel"><label for="tfeedback"><fmt:message key="jsp.feedback.form.comment"/></label></td>
76   - <td><textarea name="feedback" id="tfeedback" rows="6" cols="50"><%=StringEscapeUtils.escapeHtml(feedback)%></textarea></td>
  74 + <td class="submitFormLabel"><label for="tfeedback"><fmt:message
  75 + key="jsp.feedback.form.comment"/></label></td>
  76 + <td><textarea name="feedback" id="tfeedback" rows="6"
  77 + cols="50"><%=StringEscapeUtils.escapeHtml(feedback)%></textarea></td>
77 78 </tr>
  79 +
  80 + <%
  81 + String key = ConfigurationManager.getProperty("rcaap.google.recaptcha.sitekey");
  82 + if (key != null && !key.equals("")) {
  83 + %>
  84 + <tr>
  85 + <td>
  86 + <div align="center" class="g-recaptcha" data-sitekey="<%=key%>"></div>
  87 + </td>
  88 + </tr>
  89 + <%
  90 + }
  91 + %>
  92 +
78 93 <tr>
79 94 <td colspan="2" align="center">
80   - <input type="submit" name="submit" value="<fmt:message key="jsp.feedback.form.send"/>" />
  95 + <input type="submit" name="submit" value="<fmt:message key="jsp.feedback.form.send"/>"/>
81 96 </td>
82 97 </tr>
83 98 </table>
... ...