簡體   English   中英

Rails 5.1、Rails 6.1.3 recaptcha v3 gem 集成

[英]Rails 5.1, Rails 6.1.3 recaptcha v3 gem integration

我發現這個文檔將 rails gem recaptcha3 與設備注冊集成在一起。

https://github.com/heartcombo/devise/wiki/How-To:-Use-Recaptcha-with-Devise

所以......我將此添加到設備的注冊表中:

<%= recaptcha_v3(action: 'signup') %>

然后將其添加到控制器:

class Users::RegistrationsController < Devise::RegistrationsController

  prepend_before_action :check_captcha, only: [:create] # Change this to be any 
  actions you want to protect.

  private

  def check_captcha
    return if !verify_recaptcha # verify_recaptcha(action: 'signup') for v3

    self.resource = resource_class.new sign_up_params
    resource.validate # Look for any other validation errors besides reCAPTCHA
    set_minimum_password_length

    respond_with_navigational(resource) do
       flash.discard(:recaptcha_error) # We need to discard flash to avoid showing it 
       on the next page reload
       render :new
    end
  end
 end

然后我檢查 gem 文檔並添加:

# config/initializers/recaptcha.rb
  Recaptcha.configure do |config|
     config.site_key  = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
     config.secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

  # Uncomment the following line if you are using a proxy server:
  # config.proxy = 'http://myproxy.com.au:8080'

  # Uncomment the following lines if you are using the Enterprise API:
  # config.enterprise = true
  # config.enterprise_api_key = 'AIzvFyE3TU-g4K_Kozr9F1smEzZSGBVOfLKyupA'
  # config.enterprise_project_id = 'my-project'
end

現在怎么辦? recaptcha 是不可見的,因為在 V3 版本中它只保存一些分數。 還能用嗎?

我沒有找到任何關於設備/導軌的 recaptcha v3 的教程或幫助。

也許有人已經這樣做了?

我已經在 Rails 6 應用程序中使用了它,並帶有設計檢查此代碼https://github.com/Shaher-11/udzilla/commit/8220527e79eb49fa045fe1d7d1593031524de5a0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM