Rails 5.1、Rails 6.1.3 回顾 v3 gem 集成

Posted

技术标签:

【中文标题】Rails 5.1、Rails 6.1.3 回顾 v3 gem 集成【英文标题】:Rails 5.1, Rails 6.1.3 recaptcha v3 gem integration 【发布时间】:2021-09-30 12:20:22 【问题描述】:

我发现这个文档将 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 版本中它只保存一些分数。还能用吗?

我没有找到任何关于设备/rails 的 recaptcha v3 的教程或帮助。

也许有人已经这样做了?

【问题讨论】:

【参考方案1】:

我已经在 rails 6 应用程序中使用了它 检查此代码https://github.com/Shaher-11/udzilla/commit/8220527e79eb49fa045fe1d7d1593031524de5a0

【讨论】:

以上是关于Rails 5.1、Rails 6.1.3 回顾 v3 gem 集成的主要内容,如果未能解决你的问题,请参考以下文章

Rails 5.0 到 5.1 - 一对多关联上的“Cant cast Hash”

使用 Capistrano 部署 Rails 5.1 / Webpacker 应用程序

text 问题ao rodar“rails db:migrate”apósinstalaçãodoCKEditor no Rails 5.1

使用带有 VueJS2 的 Rails 5.1 API

禁用表单按钮,直到所有字段都填写完 rails 5.1

未初始化的常量 Faker::Date 更新到 rails 5.1