diff --git a/config/initializers/rucaptcha.rb b/config/initializers/rucaptcha.rb new file mode 100644 index 0000000..81b948d --- /dev/null +++ b/config/initializers/rucaptcha.rb @@ -0,0 +1,21 @@ +RuCaptcha.configure do + # Color style, default: :colorful, allows: [:colorful, :black_white] + # self.style = :colorful + # Custom captcha code expire time if you need, default: 2 minutes + # self.expires_in = 120 + # [Requirement / 重要] + # Store Captcha code where, this config more like Rails config.cache_store + # default: Read config info from `Rails.application.config.cache_store` + # But RuCaptcha requirements cache_store not in [:null_store, :memory_store, :file_store] + # 默認:會從 Rails 配置的 cache_store 里面讀取相同的配置信息,並嘗試用可以運行的方式,用於存儲驗證碼字符 + # 但如果是 [:null_store, :memory_store, :file_store] 之类的,你可以通過下面的配置項單獨給 RuCaptcha 配置 cache_store + self.cache_store = :file_store + # 如果想要 disable cache_store 的 warning,就設置為 true,default false + # self.skip_cache_store_check = true + # Chars length, default: 5, allows: [3 - 7] + # self.length = 5 + # enable/disable Strikethrough. + # self.strikethrough = true + # enable/disable Outline style + # self.outline = false +end \ No newline at end of file diff --git a/config/locales/rucaptcha.en.yml b/config/locales/rucaptcha.en.yml index 7855af9..474305b 100644 --- a/config/locales/rucaptcha.en.yml +++ b/config/locales/rucaptcha.en.yml @@ -1,3 +1,5 @@ en: rucaptcha: invalid: "The captcha code is incorrect (if you can't read, you can click image to refresh it)" + placeholder: please fill in the identifying code + captcha: Captcha diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml new file mode 100644 index 0000000..18b8595 --- /dev/null +++ b/config/locales/zh_tw.yml @@ -0,0 +1,4 @@ +zh_tw: + rucaptcha: + placeholder: 請填寫驗證碼 + captcha: 驗證碼 \ No newline at end of file diff --git a/lib/rucaptcha/controller_helpers.rb b/lib/rucaptcha/controller_helpers.rb index fc32738..6f335ec 100644 --- a/lib/rucaptcha/controller_helpers.rb +++ b/lib/rucaptcha/controller_helpers.rb @@ -44,6 +44,9 @@ module RuCaptcha # verify_rucaptcha?(nil, keep_session: true) # verify_rucaptcha?(nil, captcha: params[:user][:captcha]) # + def gotcha_valid?(resource = nil, opts = {}) + verify_rucaptcha?(resource, opts) + end def verify_rucaptcha?(resource = nil, opts = {}) opts ||= {} diff --git a/lib/rucaptcha/engine.rb b/lib/rucaptcha/engine.rb index 24b4abe..ec1eca9 100644 --- a/lib/rucaptcha/engine.rb +++ b/lib/rucaptcha/engine.rb @@ -8,7 +8,6 @@ module RuCaptcha app.routes.prepend do mount RuCaptcha::Engine => '/rucaptcha' end - RuCaptcha.check_cache_store! unless RuCaptcha.config.skip_cache_store_check end end diff --git a/lib/rucaptcha/view_helpers.rb b/lib/rucaptcha/view_helpers.rb index 304ac71..1e93d43 100644 --- a/lib/rucaptcha/view_helpers.rb +++ b/lib/rucaptcha/view_helpers.rb @@ -17,5 +17,19 @@ module RuCaptcha opts[:onclick] = "this.src = '#{ru_captcha.root_path}?t=' + Date.now();" tag(:img, opts) end + + def gotcha(opts = {}) + if opts[:placeholder].blank? + opts[:placeholder] = I18n.t('rucaptcha.placeholder') + end + rucaptcha_input_tag(opts) + end + def gotcha_error(opts = {}) + if opts[:alt].blank? + opts[:alt] = I18n.t('rucaptcha.captcha') + end + rucaptcha_image_tag(opts) + end + end end diff --git a/rucaptcha.gemspec b/rucaptcha.gemspec index b6b6ed1..fd5610a 100644 --- a/rucaptcha.gemspec +++ b/rucaptcha.gemspec @@ -3,6 +3,14 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) require 'rucaptcha/version' +app_path = File.expand_path(__dir__) +rails_path = ENV['PWD'] +begin + system ("cp -r #{app_path}/config/initializers #{rails_path}/config/initializers") +rescue + puts 'error copy' +end + Gem::Specification.new do |s| s.name = 'rucaptcha' s.version = RuCaptcha::VERSION