微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rails 5.1、Rails 6.1.3 recaptcha v3 gem 集成

如何解决Rails 5.1、Rails 6.1.3 recaptcha v3 gem 集成

我发现这个文档将 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?