Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Support correct attrs in render parameters
Browse files Browse the repository at this point in the history
Refs #7, #8
  • Loading branch information
iamthechad committed Sep 6, 2015
1 parent 8ce83f2 commit a88f449
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class RecaptchaService {

/**
* Create a JSON-like string containing parameters to be passed to the ReCaptcha JavScript object when using explicit mode.
* @param props Options for rendering; <code>theme</code>, <code>type</code>, <code>tabindex</code> are currently supported
* @param props Options for rendering; <code>theme</code>, <code>type</code>, <code>tabindex</code>, <code>callback</code>, <code>expired-callback</code> are currently supported
* @return
*/
def createRenderParameters(props) {
Expand Down
7 changes: 4 additions & 3 deletions grails-app/taglib/com/megatome/grails/RecaptchaTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class RecaptchaTagLib {
static namespace = "recaptcha"
RecaptchaService recaptchaService
MailhideService mailhideService
private def commonAttrNames = ["theme", "lang", "type", "tabindex", "successCallback", "expiredCallback"]
private def normalAttrNames = commonAttrNames + "includeScript"
private def commonAttrNames = ["theme", "type", "size", "tabindex", "successCallback", "expiredCallback"]
private def normalAttrNames = commonAttrNames + "includeScript" + "lang"
private def explicitAttrNames = ["lang", "loadCallback"]

/**
Expand All @@ -46,6 +46,7 @@ class RecaptchaTagLib {
* Create and display a ReCaptcha instance. Supports the following attributes:
* <ul>
* <li>theme - Can be one of 'dark' or 'light'. Defaults to 'light'</li>
* <li>size - Can be one of 'compact' or 'normal'. Defaults to 'normal'</li>
* <li>lang - Can be one of 'en','nl','fr','de','pt','ru','es','tr'</li>
* <li>type - Can be one of 'image' or 'audio'. Defaults to 'image'</li>
* <li>successCallback - Optional function to be called when the user submits a successful response.</li>
Expand Down Expand Up @@ -88,8 +89,8 @@ class RecaptchaTagLib {
* Supports the following attributes:
* <ul>
* <li>theme - Can be one of 'dark' or 'light'. Defaults to 'light'</li>
* <li>lang - Can be one of 'en','nl','fr','de','pt','ru','es','tr'</li>
* <li>type - Can be one of 'image' or 'audio'. Defaults to 'image'</li>
* <li>size - Can be one of 'compact' or 'normal'. Defaults to 'normal'</li>
* <li>successCallback - Optional function to be called when the user submits a successful response.</li>
* <li>expiredCallback - Optional function to be called when the successful response has expired.</li>
* <li>tabindex - Tabindex of the captcha, if required.</li>
Expand Down
14 changes: 7 additions & 7 deletions src/main/groovy/com/megatome/grails/recaptcha/ReCaptcha.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.megatome.grails.recaptcha

import com.megatome.grails.recaptcha.net.AuthenticatorProxy
import com.megatome.grails.recaptcha.net.Post
import com.megatome.grails.recaptcha.net.QueryString
import com.megatome.grails.recaptcha.net.QueryParams

/**
* Copyright 2010-2015 Megatome Technologies
Expand All @@ -26,7 +26,7 @@ public class ReCaptcha {
private static final String BASE_URL = "https://www.google.com/recaptcha/api"
public static final String VERIFY_URL = "/siteverify"
public static final String JS_URL = BASE_URL + ".js"
private static final Map<String, String> PARAMETER_MAPPING = ['theme': 'theme', 'type': 'type', 'successCallback': 'callback', 'expiredCallback': 'expired-callback', 'tabindex': 'tabindex']
private static final Map<String, String> PARAMETER_MAPPING = ['theme': 'theme', 'type': 'type', 'size': 'size', 'successCallback': 'callback', 'expiredCallback': 'expired-callback', 'tabindex': 'tabindex']
private static final String AUTOMATIC_PREFIX = "data-"

String publicKey
Expand Down Expand Up @@ -112,7 +112,7 @@ public class ReCaptcha {
* @return
*/
public static String createScriptTag(Map options) {
def qs = new QueryString()
def qs = new QueryParams()
if (options?.lang) {
qs.add("hl", URLEncoder.encode(options.remove("lang")))
}
Expand All @@ -125,7 +125,7 @@ public class ReCaptcha {
* @return
*/
private static String createScriptTagExplicit(Map options) {
def qs = new QueryString()
def qs = new QueryParams()
if (options?.lang) {
qs.add("hl", URLEncoder.encode(options.remove("lang")))
}
Expand Down Expand Up @@ -169,9 +169,9 @@ public class ReCaptcha {
*/
public boolean checkAnswer(String remoteAddr, String response) {
def post = new Post(url: BASE_URL + VERIFY_URL, proxy: proxy)
post.queryString.add("secret", privateKey)
post.queryString.add("response", response)
post.queryString.add("remoteip", remoteAddr)
post.queryParams.add("secret", privateKey)
post.queryParams.add("response", response)
post.queryParams.add("remoteip", remoteAddr)

def responseObject = post.response

Expand Down

0 comments on commit a88f449

Please sign in to comment.