Skip to content
Browse files

SAK-12489 trunk merge r82537

git-svn-id: https://source.sakaiproject.org/svn/user/branches/sakai-2.8.x@83178 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information...
1 parent 3ba70ae commit d8111df590c25497a0e50ca3e24aa8eca28094d2 arwhyte@umich.edu committed Oct 11, 2010
View
5 user-tool/tool/pom.xml
@@ -54,6 +54,11 @@
<groupId>org.sakaiproject</groupId>
<artifactId>sakai-velocity-tool</artifactId>
</dependency>
+ <dependency>
+ <groupId>net.tanesha.recaptcha4j</groupId>
+ <artifactId>recaptcha4j</artifactId>
+ <version>0.0.7</version>
+ </dependency>
</dependencies>
<build>
<resources>
View
1 user-tool/tool/src/bundle/admin.properties
@@ -12,6 +12,7 @@ useact.youdonot2 = You do not have permission to remove User
useact.youdonot3 = You do not have permission to edit this User
useact.tryloginagain = Account created, but unable to process the login. Please try to login again.
useact.invemail = The email address is invalid
+useact.capterr = There was a problem with the captcha.
#merged all duplicates- SAK-18304
View
54 user-tool/tool/src/java/org/sakaiproject/user/tool/UsersAction.java
@@ -27,6 +27,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import net.tanesha.recaptcha.ReCaptcha;
+import net.tanesha.recaptcha.ReCaptchaFactory;
+import net.tanesha.recaptcha.ReCaptchaResponse;
+
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.EmailValidator;
import org.sakaiproject.authz.cover.SecurityService;
@@ -129,6 +133,31 @@ protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRu
{
state.setAttribute("create-type", config.getInitParameter("create-type", ""));
}
+
+ if (state.getAttribute("recaptcha-enabled") == null)
+ {
+ String publicKey = ServerConfigurationService.getString("recaptcha.public-key", "");
+ String privateKey = ServerConfigurationService.getString("recaptcha.private-key", "");
+ Boolean systemEnabled = ServerConfigurationService.getBoolean("recaptcha.enabled", false);
+ Boolean toolEnabled = Boolean.parseBoolean(config.getInitParameter("recaptcha-enabled", "false"));
+ Boolean enabled = systemEnabled && toolEnabled;
+ if (enabled)
+ {
+ if (publicKey == null || publicKey.length() == 0)
+ {
+ Log.warn("chef", "recaptcha is enabled but no public key is found.");
+ enabled = Boolean.FALSE;
+ }
+ if (privateKey == null || privateKey.length() == 0)
+ {
+ Log.warn("chef", "recaptcha is enabled but no private key is found.");
+ enabled = Boolean.FALSE;
+ }
+ }
+ state.setAttribute("recaptcha-public-key", publicKey);
+ state.setAttribute("recaptcha-private-key", privateKey);
+ state.setAttribute("recaptcha-enabled", enabled);
+ }
} // initState
@@ -341,6 +370,14 @@ private String buildCreateContext(SessionState state, Context context)
value = (String) state.getAttribute("valueEmail");
if (value != null) context.put("valueEmail", value);
+
+ if ((Boolean)state.getAttribute("recaptcha-enabled"))
+ {
+ ReCaptcha captcha = ReCaptchaFactory.newReCaptcha((String)state.getAttribute("recaptcha-public-key"), (String)state.getAttribute("recaptcha-private-key"), false);
+ String captchaScript = captcha.createRecaptchaHtml((String)state.getAttribute("recaptcha-error"), null);
+ state.removeAttribute("recaptcha-error");
+ context.put("recaptchaScript", captchaScript);
+ }
return "_create";
@@ -842,6 +879,23 @@ else if ((mode != null) && (mode.equalsIgnoreCase("edit")) && (!singleUser))
}
}
+ if ((Boolean)state.getAttribute("recaptcha-enabled"))
+ {
+ String challengeField = data.getParameters().getString("recaptcha_challenge_field");
+ String responseField = data.getParameters().getString("recaptcha_response_field");
+ if (challengeField == null) challengeField = "";
+ if (responseField == null) responseField = "";
+ ReCaptcha captcha = ReCaptchaFactory.newReCaptcha((String)state.getAttribute("recaptcha-public-key"), (String)state.getAttribute("recaptcha-private-key"), false);
+ ReCaptchaResponse response = captcha.checkAnswer(data.getRequest().getRemoteAddr(), challengeField, responseField);
+ if (!response.isValid())
+ {
+ addAlert(state, rb.getString("useact.capterr"));
+ state.setAttribute("recaptcha-error", response.getErrorMessage());
+ return false;
+ }
+ }
+
+
//insure valid email address
//email.matches(".+@.+\\..+")
if(email != null && !EmailValidator.getInstance().isValid(email)) {
View
1 user-tool/tool/src/webapp/tools/sakai.createuser.xml
@@ -12,6 +12,7 @@
<configuration name="create-login" value="true" type="final" />
<configuration name="create-user" value="true" type="final" />
<configuration name="reset.button" value="false" type="final" />
+ <configuration name="recaptcha-enabled" value="true"/>
</tool>
View
1 user-tool/tool/src/webapp/vm/user/chef_users_create.vm
@@ -61,6 +61,7 @@
<input disabled type="text" name="dtype" id="dtype" value="$type"/>
<input type="hidden" name="type" id="type" value="$type"/>
</p>
+ $!recaptchaScript
<div class="act">
<input type="submit" class="active" name="eventSubmit_doSave" value="$tlang.getString("usecre.creaco")" accesskey="s" />
<input type="submit" name="eventSubmit_doCancel" value="$tlang.getString("useconrem.can")" accesskey="x" />

0 comments on commit d8111df

Please sign in to comment.
Something went wrong with that request. Please try again.