Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finish quickstart script.

  • Loading branch information...
commit 84855210ad0925071c619101f9a08c12271f7ddb 1 parent b9cfa2d
@iamthechad authored
Showing with 84 additions and 20 deletions.
  1. +75 −3 scripts/RecaptchaQuickstart.groovy
  2. +9 −17 scripts/_Install.groovy
View
78 scripts/RecaptchaQuickstart.groovy
@@ -8,15 +8,18 @@ If 'integrated' is specified, entries are created in Config.groovy.
If 'standalone' is specified, then RecaptchaConfig.groovy is created.
"""
+appDir = "$basedir/grails-app"
+templateDir = "$recaptchaPluginDir/src/templates"
+
target(main: "Create default ReCaptcha configuration") {
def argValue = parseArgs()
if (!argValue) {
return 1
}
if ("standalone" == argValue) {
- updateConfig()
- } else if ("integrated" == argValue) {
copyConfig()
+ } else if ("integrated" == argValue) {
+ updateConfig()
}
printMessage """
@@ -31,7 +34,7 @@ private parseArgs() {
def args = argsMap.params
if (1 == args.size()) {
- if ("standalone" == $args[0]) {
+ if ("standalone" == args[0]) {
printMessage "Creating standalone ReCaptcha configuration in RecaptchaConfig.groovy"
} else if ("integrated" == args[0]) {
printMessage "Creating ReCapctcha configuration in Config.groovy"
@@ -46,6 +49,75 @@ private parseArgs() {
null
}
+private void updateConfig() {
+
+ def configFile = new File(appDir, 'conf/Config.groovy')
+ if (configFile.exists()) {
+ configFile.withWriterAppend {
+ it.write """
+\n// Added by the Recaptcha plugin:
+recaptcha {
+ // These keys are generated by the ReCaptcha service
+ publicKey = ""
+ privateKey = ""
+
+ // Include the noscript tags in the generated captcha
+ includeNoScript = true
+
+ // Force language change. See this for more: http://code.google.com/p/recaptcha/issues/detail?id=133
+ forceLanguageInURL = false
+
+ // Set to false to disable the display of captcha
+ enabled = true
+
+ // Communicate using HTTPS
+ useSecureAPI = true
+}
+
+mailhide {
+ // Generated by the Mailhide service
+ publicKey = ""
+ privateKey = ""
+}
+"""
+ }
+ }
+}
+
+okToWrite = { String dest ->
+
+ def file = new File(dest)
+ if (!file.exists()) {
+ return true
+ }
+
+ String propertyName = "file.overwrite.$file.name"
+ ant.input(addProperty: propertyName, message: "$dest exists, ok to overwrite?",
+ validargs: 'y,n,a', defaultvalue: 'y')
+
+ if (ant.antProject.properties."$propertyName" == 'n') {
+ return false
+ }
+
+ if (ant.antProject.properties."$propertyName" == 'a') {
+ overwriteAll = true
+ }
+
+ true
+}
+
+copyFile = { String from, String to ->
+ if (!okToWrite(to)) {
+ return
+ }
+
+ ant.copy file: from, tofile: to, overwrite: true
+}
+
+private void copyConfig() {
+ copyFile "$templateDir/RecaptchaConfig.groovy", "$appDir/conf/RecaptchaConfig.groovy"
+}
+
printMessage = { String message -> event('StatusUpdate', [message]) }
errorMessage = { String message -> event('StatusError', [message]) }
View
26 scripts/_Install.groovy
@@ -1,17 +1,9 @@
-
-//
-// This script is executed by Grails after plugin was installed to project.
-// This script is a Gant script so you can use all special variables provided
-// by Gant (such as 'baseDir' which points on project base dir). You can
-// use 'Ant' to access a global instance of AntBuilder
-//
-//
-if (!ant.available(file: "${basedir}/grails-app/conf/RecaptchaConfig.groovy")) {
-
- ant.copy(file:"${pluginBasedir}/src/templates/RecaptchaConfig.groovy",
- todir:"${basedir}/grails-app/conf")
-}
-
-ant.property(environment:"env")
-grailsHome = ant.antProject.properties."env.GRAILS_HOME"
-
+println '''
+*******************************************************
+* You've installed the Recaptcha plugin. *
+* *
+* Next run the "recaptcha-quickstart" script to *
+* initialize the configuration. *
+* *
+*******************************************************
+'''
Please sign in to comment.
Something went wrong with that request. Please try again.