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

Commit

Permalink
Use static types where possible
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
iamthechad committed Apr 30, 2018
1 parent 3a919f0 commit 34c80b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions grails-app/services/com/megatome/grails/RecaptchaService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.megatome.grails.recaptcha.ReCaptcha
import com.megatome.grails.recaptcha.net.AuthenticatorProxy
import com.megatome.grails.util.ConfigHelper
import grails.util.Environment
import org.grails.config.NavigableMap

/**
* Copyright 2010-2018 Megatome Technologies
Expand All @@ -24,8 +25,8 @@ import grails.util.Environment
class RecaptchaService {
boolean transactional = false
def grailsApplication
private def recaptchaConfig = null
private def recap = null
private NavigableMap recaptchaConfig = null
private ReCaptcha recap = null

/**
* Gets the ReCaptcha config.
Expand Down Expand Up @@ -55,7 +56,7 @@ class RecaptchaService {
return this.recaptchaConfig
}

private def getRecaptchaInstance() {
private ReCaptcha getRecaptchaInstance() {
if (!recap) {
// Public key, private key, include noscript, include script, proxy config
def config = getRecaptchaConfig()
Expand All @@ -76,7 +77,7 @@ class RecaptchaService {
recap
}

private boolean safeGetConfigValue(def value, def defaultValue) {
private boolean safeGetConfigValue(String value, boolean defaultValue) {
def config = getRecaptchaConfig()
if (config.containsKey(value)) {
return ConfigHelper.booleanValue(config[value])
Expand All @@ -94,7 +95,7 @@ class RecaptchaService {
*
* @return HTML code, suitable for embedding into a webpage.
*/
def createCaptcha(props) {
String createCaptcha(props) {
return getRecaptchaInstance().createRecaptchaHtml(props)
}

Expand All @@ -105,7 +106,7 @@ class RecaptchaService {
* @param props Options for rendering; <code>lang</code>, and <code>loadCallback</code> are currently supported by recaptcha.
* @return HTML code, suitable for embedding into a webpage.
*/
def createCaptchaExplicit(props) {
String createCaptchaExplicit(props) {
return getRecaptchaInstance().createRecaptchaExplicitHtml(props)
}

Expand All @@ -114,7 +115,7 @@ class RecaptchaService {
* @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) {
String createRenderParameters(props) {
return getRecaptchaInstance().createRenderParameters(props)
}

Expand All @@ -126,7 +127,7 @@ class RecaptchaService {
*
* @return HTML code, suitable for embedding into a webpage.
*/
def createScriptEntry(props) {
String createScriptEntry(props) {
return getRecaptchaInstance().createScriptTag(props)
}

Expand All @@ -139,7 +140,7 @@ class RecaptchaService {
*
* @return True if the supplied answer is correct, false otherwise. Returns true if ReCaptcha support is disabled.
*/
def verifyAnswer(session, remoteAddress, params) {
boolean verifyAnswer(session, remoteAddress, params) {
if (!isEnabled()) {
return true
}
Expand All @@ -152,7 +153,7 @@ class RecaptchaService {
/**
* Get a value indicating if the ReCaptcha plugin should be enabled.
*/
def isEnabled() {
boolean isEnabled() {
return safeGetConfigValue('enabled', true)
}

Expand All @@ -161,7 +162,7 @@ class RecaptchaService {
*
* @param session The current session
*/
def validationFailed(session) {
boolean validationFailed(session) {
return (session["recaptcha_error"] != null)
}

Expand All @@ -171,7 +172,7 @@ class RecaptchaService {
*
* @param session The current session.
*/
def cleanUp(session) {
void cleanUp(session) {
session["recaptcha_error"] = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AuthenticatorProxy {
int port = -1
String username = null
String password = null
private def proxy = null
private Proxy proxy = null

public AuthenticatorProxy(Map map) {
map.each { k,v -> if (this.hasProperty(k)) { this."$k" = v} }
Expand Down

0 comments on commit 34c80b1

Please sign in to comment.