lib/tasks/textcaptcha.rake in acts_as_textcaptcha-2.2.2 vs lib/tasks/textcaptcha.rake in acts_as_textcaptcha-3.0.0
- old
+ new
@@ -1,23 +1,26 @@
+require 'bcrypt'
+
namespace :textcaptcha do
- desc "Adds a textcaptcha.yml template config file to ./config "
- task :generate_config do
+ desc "Creates a template config file in config/textcaptcha.yml"
+ task :config do
src = File.join(File.dirname(__FILE__), '../..', 'config', 'textcaptcha.yml')
dest = File.join(Rails.root, 'config', 'textcaptcha.yml')
if File.exist?(dest)
- puts "\ntextcaptcha config file: #{dest}\n ... already exists. Aborting.\n\n"
+ puts "\nOoops, a textcaptcha config file at #{dest} already exists ... aborting.\n\n"
else
- config_file = ''
+ config = ''
+ salt = BCrypt::Engine.generate_salt
f = File.open(src, 'r')
- f.each_line { |line| config_file += line }
- config_file.gsub!(/api\_key\:(.+)$/, 'api_key: # get one at http://textcaptcha.com' )
- config_file.gsub!(/bcrypt\_salt\:(.+)$/, "bcrypt_salt: #{BCrypt::Engine.generate_salt}" ) if defined?(BCrypt)
+ f.each_line { |line| config += line }
+ config.gsub!(/RAKE_GENERATED_SALT_PLACEHOLDER/, salt)
+ config.gsub!(/ api_key:(.*)# for gem test purposes only$/, " api_key: PASTE_YOUR_TEXTCAPCHA_API_KEY_HERE")
+ config.gsub!(/ bcrypt_salt:(.*)# for gem test purposes only$/, " bcrypt_salt: #{salt}")
f = File.new(dest, 'w')
- f.write(config_file)
+ f.write(config)
f.close
- puts "\ntextcaptcha.yml generated at #{dest} (with a new BCrypt salt).\nNOTE: edit this file and add your textcaptcha api key (from http://textcaptcha.com)"
+ puts "\ntextcaptcha.yml generated at #{dest} (with a new BCrypt salt)\nNOTE: edit this file and add your textcaptcha api key, grab one from http://textcaptcha.com/api\n\n"
end
-
end
-end
\ No newline at end of file
+end