diff -u -r dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemRequestForm.java dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemRequestForm.java --- dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemRequestForm.java 2015-11-09 17:43:01.000000000 +0700 +++ dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/ItemRequestForm.java 2015-11-10 18:04:17.442267000 +0700 @@ -172,6 +172,9 @@ TextArea message = form.addItem().addTextArea("message"); message.setLabel(T_message); message.setValue(parameters.getParameter("message", "")); + + form.addItem().addSpan("g-recaptcha"); + form.addItem().addHidden("bitstreamId").setValue(parameters.getParameter("bitstreamId", "")); form.addItem().addButton("submit").setValue(T_submit); diff -u -r dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendItemRequestAction.java dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendItemRequestAction.java --- dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendItemRequestAction.java 2015-11-09 17:43:01.000000000 +0700 +++ dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendItemRequestAction.java 2015-11-10 18:04:17.484669000 +0700 @@ -38,6 +38,10 @@ import org.dspace.storage.rdbms.DatabaseManager; import org.dspace.storage.rdbms.TableRow; import org.dspace.utils.DSpace; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.util.EncodingUtil; +import org.apache.commons.httpclient.methods.PostMethod; /** * This action will send a mail to request a item to administrator when all mandatory data is present. @@ -50,6 +54,30 @@ */ public class SendItemRequestAction extends AbstractAction { + + private Boolean validarCaptcha(String captcha) throws Exception { + if(!"".equals(captcha)){ + String secret="XXX reCaptcha SECRET KEY XXX"; + String url="https://www.google.com/recaptcha/api/siteverify"; + NameValuePair args[] = new NameValuePair[2]; + args[0] = new NameValuePair("secret", secret); + args[1] = new NameValuePair("response", captcha); + + HttpClient hc = new HttpClient(); + String srUrl = url + "?" + EncodingUtil.formUrlEncode(args, "UTF8"); + + PostMethod post=new PostMethod(srUrl); + int status = hc.executeMethod(post); //get.getResponseBodyAsString() + if (status == 200){ + //TODO hacerlo BIEN + return post.getResponseBodyAsString().contains("true"); + + } + } + return false; + } + + private static Logger log = Logger.getLogger(SendItemRequestAction.class); public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, @@ -62,7 +90,23 @@ String allFiles = request.getParameter("allFiles"); String message = request.getParameter("message"); String bitstreamId = request.getParameter("bitstreamId"); - + + boolean valido=true; + try{ + String p=request.getParameter("g-recaptcha-response"); + if(p==null){ + valido=false; + } else if("".equals(p)){ + valido=false; + } else{ + valido=validarCaptcha(p); + } + + } + catch(Exception e){ + valido=false; + } + // User email from context Context context = ContextUtil.obtainContext(objectModel); EPerson loggedin = context.getCurrentUser(); @@ -73,7 +117,7 @@ } // Check all data is there - if (StringUtils.isEmpty(requesterName) || StringUtils.isEmpty(requesterEmail) || StringUtils.isEmpty(allFiles) || StringUtils.isEmpty(message)) + if (StringUtils.isEmpty(requesterName) || StringUtils.isEmpty(requesterEmail) || StringUtils.isEmpty(allFiles) || StringUtils.isEmpty(message) || !valido) { // Either the user did not fill out the form or this is the // first time they are visiting the page. diff -u -r dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/wing/element/Item.java dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/wing/element/Item.java --- dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/wing/element/Item.java 2015-11-09 17:43:01.000000000 +0700 +++ dspace-4.2-src-release/dspace-xmlui/src/main/java/org/dspace/app/xmlui/wing/element/Item.java 2015-11-10 18:16:45.000000000 +0700 @@ -29,6 +29,25 @@ public class Item extends RichTextContainer implements StructuralElement { + + public Span addSpan() throws WingException + { + return addSpan(null,null); + } + + public Span addSpan(String name) throws WingException + { + return addSpan(name,null); + } + + + public Span addSpan(String name, String rend) throws WingException{ + Span div=new Span(context, name, rend); + contents.add(div); + return div; + + } + /** The name of the item element */ public static final String E_ITEM = "item"; diff -u -r dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/Mirage/lib/xsl/core/page-structure.xsl dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/Mirage/lib/xsl/core/page-structure.xsl --- dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/Mirage/lib/xsl/core/page-structure.xsl 2015-11-09 17:43:02.000000000 +0700 +++ dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/Mirage/lib/xsl/core/page-structure.xsl 2015-11-09 18:10:46.000000000 +0700 @@ -693,6 +693,11 @@ + + + + diff -u -r dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/dri2xhtml-alt/core/elements.xsl dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/dri2xhtml-alt/core/elements.xsl --- dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/dri2xhtml-alt/core/elements.xsl 2015-11-09 17:43:01.000000000 +0700 +++ dspace-4.2-src-release/dspace-xmlui/src/main/webapp/themes/dri2xhtml-alt/core/elements.xsl 2015-11-09 18:19:10.000000000 +0700 @@ -43,41 +43,53 @@ handle the attributes, and then apply the templates for the all children except the head. The id attribute is --> - - - top - -
+ + + top + +
+ + + + + + + XXX reCaptcha SITE KEY XXX + + - ds-static-div + ds-static-div - - - - - - -   - - -
- - - - - - - - - - - - - bottom - + + + + + + +   + + + + +
+ + + + + + + + + + + + + bottom +
- +