diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/beans/RefreshCaptchaController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/beans/RefreshCaptchaController.java new file mode 100644 index 0000000000..958183e00a --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/beans/RefreshCaptchaController.java @@ -0,0 +1,31 @@ +package edu.cornell.mannlib.vitro.webapp.beans; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.twelvemonkeys.servlet.HttpServlet; + +@WebServlet(name = "refreshCaptcha", urlPatterns = {"/refreshCaptcha"}, loadOnStartup = 5) +public class RefreshCaptchaController extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String oldChallengeId = request.getParameter("oldChallengeId"); + + response.setContentType("application/json"); + PrintWriter out = response.getWriter(); + + CaptchaBundle newChallenge = CaptchaServiceBean.generateChallenge(); + CaptchaServiceBean.getCaptchaChallenges().invalidate(oldChallengeId); + CaptchaServiceBean.getCaptchaChallenges().put(newChallenge.getCaptchaId(), newChallenge); + + out.println("{\"challenge\": \"" + newChallenge.getB64Image() + "\", \"challengeId\": \"" + + newChallenge.getCaptchaId() + "\"}"); + } + +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactFormController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactFormController.java index afebb46fe0..1d0ad6e1f0 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactFormController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactFormController.java @@ -80,6 +80,7 @@ else if (StringUtils.isBlank(appBean.getContactMail())) { body.put("challengeId", captchaChallenge.getCaptchaId()); } + body.put("contextPath", vreq.getContextPath()); body.put("formAction", "submitFeedback"); body.put("captchaToUse", captchaImpl); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java index 20a49ba4aa..3910ddf0f0 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java @@ -421,6 +421,7 @@ private ResponseValues errorParametersNotValid(String errorMsg, String webuserna body.put("webuseremail", webuseremail); body.put("comments", comments); body.put("captchaToUse", captchaImpl); + body.put("contextPath", vreq.getContextPath()); if (!captchaImpl.equals("RECAPTCHA")) { CaptchaBundle captchaChallenge = CaptchaServiceBean.generateChallenge(); diff --git a/webapp/src/main/webapp/templates/freemarker/body/contactForm/contactForm-form.ftl b/webapp/src/main/webapp/templates/freemarker/body/contactForm/contactForm-form.ftl index 29a4f9d8f1..80012d69b8 100644 --- a/webapp/src/main/webapp/templates/freemarker/body/contactForm/contactForm-form.ftl +++ b/webapp/src/main/webapp/templates/freemarker/body/contactForm/contactForm-form.ftl @@ -37,7 +37,11 @@

- Refresh page if not displayed... +

+ + Refresh page if not displayed... +
+

@@ -71,4 +75,27 @@ ${scripts.add('